patch for st-1.5.0: st_recvmsg/st_sendmsg
Claus Assmann <[email protected]> Fri, 21 May 2004 07:38:14 -0700
| Newsgroups | gmane.comp.lib.state-threads.devel |
|---|---|
| Message-ID | <[email protected]> |
--/9DWx/yDrRhgMJTb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
For my project I need to transfer file descriptors between applications
and the example from Stevens book uses recvmsg()/sendmsg(), hence
I added those two function to statethreads. The patch is attached.
Would it make sense to add this to the distribution or is it just
overhead that other people don't need?
--/9DWx/yDrRhgMJTb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="d.st-1.5.0-p0"
diff -u -w -r st-1.5.0/common.h statethreads/common.h
--- st-1.5.0/common.h Sun Jan 11 14:18:15 2004
+++ statethreads/common.h Fri Jan 16 13:58:05 2004
@@ -352,7 +354,10 @@
#define ST_DEFAULT_STACK_SIZE (128*1024) /* Includes register stack size */
#endif
#define ST_KEYS_MAX 16
+/* XXX increase this? to avoid malloc() failure later on? */
+#ifndef ST_MIN_POLLFDS_SIZE
#define ST_MIN_POLLFDS_SIZE 64
+#endif /* ST_MIN_POLLFDS_SIZE */
/*****************************************
diff -u -w -r st-1.5.0/io.c statethreads/io.c
--- st-1.5.0/io.c Thu Mar 28 21:09:08 2002
+++ statethreads/io.c Wed Apr 9 10:57:24 2003
@@ -633,6 +635,45 @@
return n;
}
+
+int st_recvmsg(_st_netfd_t *fd, struct msghdr *msg, int flags,
+ st_utime_t timeout)
+{
+ int n;
+
+ while ((n = recvmsg(fd->osfd, msg, flags))
+ < 0) {
+ if (errno == EINTR)
+ continue;
+ if (!_IO_NOT_READY_ERROR)
+ return -1;
+ /* Wait until the socket becomes readable */
+ if (st_netfd_poll(fd, POLLIN, timeout) < 0)
+ return -1;
+ }
+
+ return n;
+}
+
+
+int st_sendmsg(_st_netfd_t *fd, const struct msghdr *msg, int flags,
+ st_utime_t timeout)
+{
+ int n;
+
+ while ((n = sendmsg(fd->osfd, msg, flags)) < 0) {
+ if (errno == EINTR)
+ continue;
+ if (!_IO_NOT_READY_ERROR)
+ return -1;
+ /* Wait until the socket becomes writable */
+ if (st_netfd_poll(fd, POLLOUT, timeout) < 0)
+ return -1;
+ }
+
+ return n;
+}
+
/*
diff -u -w -r st-1.5.0/public.h statethreads/public.h
--- st-1.5.0/public.h Thu Mar 28 21:09:08 2002
+++ statethreads/public.h Wed Apr 9 10:57:24 2003
@@ -154,6 +156,11 @@
extern int st_sendto(st_netfd_t fd, const void *msg, int len,
const struct sockaddr *to, int tolen, st_utime_t timeout);
extern st_netfd_t st_open(const char *path, int oflags, mode_t mode);
+
+extern int st_recvmsg(st_netfd_t fd, struct msghdr *msg, int flags,
+ st_utime_t timeout);
+extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags,
+ st_utime_t timeout);
#ifdef DEBUG
extern void _st_show_thread_stack(st_thread_t thread, const char *messg);
--/9DWx/yDrRhgMJTb--
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click