aboutsummaryrefslogtreecommitdiff
path: root/jim-aio.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2016-02-01 15:42:09 +1000
committerSteve Bennett <steveb@workware.net.au>2016-02-01 15:52:10 +1000
commit2d39166b9970cd0954238ee80e8ab63a8d0bb47d (patch)
treebb045da71fdaa7eae928cefca94c24d70ee86def /jim-aio.c
parent54697b4bebf26e80d60e7a10d42fc5f4f00b9fdd (diff)
downloadjimtcl-2d39166b9970cd0954238ee80e8ab63a8d0bb47d.zip
jimtcl-2d39166b9970cd0954238ee80e8ab63a8d0bb47d.tar.gz
jimtcl-2d39166b9970cd0954238ee80e8ab63a8d0bb47d.tar.bz2
aio: fix aio ssl support
The following changes were not merged: - commit examples/{certificate,key}.pem - return AioFile from JimMakeChannel to allow ssl-specific settings to be set - improve examples/ssl.{client,server} so they work out-of-the-box Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-aio.c')
-rw-r--r--jim-aio.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/jim-aio.c b/jim-aio.c
index 9463bda..87834a7 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -273,7 +273,7 @@ static const JimAioFopsType ssl_fops = {
#endif
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
-static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
+static AioFile *JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
const char *hdlfmt, int family, const char *mode);
#if !defined(JIM_ANSIC) && !defined(JIM_BOOTSTRAP)
@@ -803,7 +803,7 @@ static int aio_cmd_accept(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
/* Create the file command */
return JimMakeChannel(interp, NULL, sock, Jim_NewStringObj(interp, "accept", -1),
- "aio.sockstream%ld", af->addr_family, "r+");
+ "aio.sockstream%ld", af->addr_family, "r+") ? JIM_OK : JIM_ERR;
}
static int aio_cmd_listen(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -1118,7 +1118,8 @@ static int aio_cmd_ssl(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
}
}
- if (JimMakeChannel(interp, NULL, fd, NULL, "aio.sslstream%ld", af->addr_family, "r+") != JIM_OK) {
+ af = JimMakeChannel(interp, NULL, fd, NULL, "aio.sslstream%ld", af->addr_family, "r+");
+ if (af == NULL) {
goto out;
}
@@ -1153,7 +1154,6 @@ static int aio_cmd_verify(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_SetResultString(interp, "failed to verify the connection authenticity", -1);
}
}
-
return ret;
}
#endif
@@ -1368,7 +1368,7 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
}
}
#endif
- return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode);
+ return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode) ? JIM_OK : JIM_ERR;
}
#if defined(JIM_SSL)
@@ -1407,8 +1407,9 @@ static SSL_CTX *JimAioSslCtx(Jim_Interp *interp)
* mode is used for open or fdopen.
*
* Creates the command and sets the name as the current result.
+ * Returns the AioFile pointer on sucess or NULL on failure.
*/
-static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
+static AioFile *JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
const char *hdlfmt, int family, const char *mode)
{
AioFile *af;
@@ -1445,7 +1446,7 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
}
#endif
Jim_DecrRefCount(interp, filename);
- return JIM_ERR;
+ return NULL;
}
}
@@ -1463,6 +1464,7 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
af->openFlags = openFlags;
af->addr_family = family;
af->fops = &stdio_fops;
+ af->ssl = NULL;
Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
@@ -1471,7 +1473,7 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
*/
Jim_SetResult(interp, Jim_MakeGlobalNamespaceName(interp, Jim_NewStringObj(interp, buf, -1)));
- return JIM_OK;
+ return af;
}
#if defined(HAVE_PIPE) || (defined(HAVE_SOCKETPAIR) && defined(HAVE_SYS_UN_H))
@@ -1481,11 +1483,11 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
static int JimMakeChannelPair(Jim_Interp *interp, int p[2], Jim_Obj *filename,
const char *hdlfmt, int family, const char *mode[2])
{
- if (JimMakeChannel(interp, NULL, p[0], filename, hdlfmt, family, mode[0]) == JIM_OK) {
+ if (JimMakeChannel(interp, NULL, p[0], filename, hdlfmt, family, mode[0])) {
Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
- if (JimMakeChannel(interp, NULL, p[1], filename, hdlfmt, family, mode[1]) == JIM_OK) {
+ if (JimMakeChannel(interp, NULL, p[1], filename, hdlfmt, family, mode[1])) {
Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
Jim_SetResult(interp, objPtr);
return JIM_OK;
@@ -1765,7 +1767,7 @@ static int JimAioSockCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_ERR;
}
- return JimMakeChannel(interp, NULL, sock, argv[1], hdlfmt, family, mode);
+ return JimMakeChannel(interp, NULL, sock, argv[1], hdlfmt, family, mode) ? JIM_OK : JIM_ERR;
}
#endif /* JIM_BOOTSTRAP */