aboutsummaryrefslogtreecommitdiff
path: root/jim-aio.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2013-11-26 08:48:14 +1000
committerSteve Bennett <steveb@workware.net.au>2013-12-21 01:08:24 +1000
commit348cf1a55c8ed2442d58ec29034966ba1d05980e (patch)
treea05dd33cdcab12bc30aea5de2ba6c6c4d27e6a7f /jim-aio.c
parentdd766b8642398684da5bf70f4f346301bc9da01c (diff)
downloadjimtcl-348cf1a55c8ed2442d58ec29034966ba1d05980e.zip
jimtcl-348cf1a55c8ed2442d58ec29034966ba1d05980e.tar.gz
jimtcl-348cf1a55c8ed2442d58ec29034966ba1d05980e.tar.bz2
aio: add support for half-close
Currently only for sockets since Jim Tcl does not support bidirectional pipes. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-aio.c')
-rw-r--r--jim-aio.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/jim-aio.c b/jim-aio.c
index fc80307..4ccdae4 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -667,6 +667,26 @@ static int aio_cmd_eof(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static int aio_cmd_close(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
+ if (argc == 3) {
+#ifdef HAVE_SHUTDOWN
+ static const char * const options[] = { "r", "w", NULL };
+ enum { OPT_R, OPT_W, };
+ int option;
+ AioFile *af = Jim_CmdPrivData(interp);
+
+ if (Jim_GetEnum(interp, argv[2], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
+ return JIM_ERR;
+ }
+ if (shutdown(af->fd, option == OPT_R ? SHUT_RD : SHUT_WR) == 0) {
+ return JIM_OK;
+ }
+ JimAioSetError(interp, NULL);
+#else
+ Jim_SetResultString(interp, "async close not supported", -1);
+#endif
+ return JIM_ERR;
+ }
+
return Jim_DeleteCommand(interp, Jim_String(argv[0]));
}
@@ -926,12 +946,12 @@ static const jim_subcmd_type aio_command_table[] = {
/* Description: Returns 1 if stream is at eof */
},
{ "close",
- NULL,
+ "?r(ead)|w(rite)?",
aio_cmd_close,
0,
- 0,
+ 1,
JIM_MODFLAG_FULLARGV,
- /* Description: Closes the stream */
+ /* Description: Closes the stream. */
},
{ "seek",
"offset ?start|current|end",