Add shutdown to client_socket for testing
@@ -185,6 +185,40 @@ lreadstdin(lua_State *L) {
return 1;
}
+static int
+lshutdown(lua_State *L) {
+ int fd = luaL_checkinteger(L,1);
+ const char *mode = luaL_checkstring(L,2);
+ int v = 0;
+ int i;
+ int read = 1;
+ int write = 2;
+ for (i=0;mode[i];i++) {
+ switch(mode[i]) {
+ case 'r':
+ v |= read;
+ break;
+ case 'w':
+ v |= write;
+ break;
+ default:
+ return luaL_error(L, "Invalid mode %c", mode[i]);
+ }
+ }
+ if (v == 0) {
+ return luaL_error(L, "mode should be r or/and w");
+ }
+ if (v == read)
+ v = SHUT_RD;
+ else if (v == write)
+ v = SHUT_WR;
+ else
+ v = SHUT_RDWR;
+ printf("SHUTDOWN %d %d\n", fd, v);
+ shutdown(fd, v);
+ return 0;
+}
+
LUAMOD_API int
luaopen_client_socket(lua_State *L) {
luaL_checkversion(L);
@@ -192,6 +226,7 @@ luaopen_client_socket(lua_State *L) {
{ "connect", lconnect },
{ "recv", lrecv },
{ "send", lsend },
+ { "shutdown", lshutdown },
{ "close", lclose },
{ "usleep", lusleep },
{ NULL, NULL },
