Hello,
I am currently searching for the eCS pendants of constants that are used by C's
`shutdown` function.
The constants SD_* and SHUT_* do not seem to exist in eCS.
Would you please help me ?
Thank you,
Alex
#ifdef _WIN32
# define SHUTDOWN_RD SD_RECEIVE
# define SHUTDOWN_WR SD_SEND
# define SHUTDOWN_RDWR SD_BOTH
#else
# define SHUTDOWN_RD SHUT_RD
# define SHUTDOWN_WR SHUT_WR
# define SHUTDOWN_RDWR SHUT_RDWR
#endif
static int net_shutdown (lua_State *L) {
const char *mode;
int r, m;
AGN_SOCKET sock;
STATUS *s;
sock = luaL_checkinteger(L, 1);
checksocket(L, sock, AGN_NET_SHUTDOWN);
s = getsocketattribs(L, sock, AGN_NET_SHUTDOWN);
if (!s->connected) {
agn_neterrorfail(L, "socket not connected");
}
mode = luaL_checkstring(L, 2);
if (strcmp(mode, "read") == 0) {
r = shutdown(sock, SHUTDOWN_RD); m = SHUTDOWN_RD;
} else if (strcmp(mode, "write") == 0) {
r = shutdown(sock, SHUTDOWN_WR); m = SHUTDOWN_WR;
} else if (strcmp(mode, "readwrite") == 0) {
r = shutdown(sock, SHUTDOWN_RDWR); m = SHUTDOWN_RDWR;
} else {
m = r = -MAX_INT;
luaL_error(L, "Error in " LUA_QS ": unknown shutdown mode `%s`." AGN_NET_SHUTDOWN, mode);
}
if (r == 0) {
s->shutdown = m;
if (treeupdate(socketattribs, sock, s) != 0) {
luaL_error(L, "Error in " LUA_QS ": could not assign socket to administration table.", AGN_NET_SHUTDOWN);
}
}
lua_pushboolean(L, r == 0);
return 1;
}