]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
Introduce lwip_getsock_status()
authorYuri Volchkov <yuri.volchkov@neclab.eu>
Tue, 20 Mar 2018 12:30:10 +0000 (13:30 +0100)
committerSimon Kuenzer <simon.kuenzer@neclab.eu>
Thu, 14 Jun 2018 23:26:45 +0000 (01:26 +0200)
This function is intended to be used for implementing poll().
It returns a status flag for a socket fd. It is added as patch to
the lwIP sources.

Signed-off-by: Yuri Volchkov <yuri.volchkov@neclab.eu>
include/arch/sys_arch.h
patches/0002-introduce-lwip_getsock_status.patch [new file with mode: 0644]

index 7efec566c62a44d6d26da55be645a51b2ae443a8..93dfc957c080be7bd8f27f5204e86da12377572c 100644 (file)
@@ -10,6 +10,8 @@
 #ifndef __LWIP_ARCH_SYS_ARCH_H__
 #define __LWIP_ARCH_SYS_ARCH_H__
 
+#include <uk/config.h>
+
 #include <stdlib.h>
 #include <uk/mutex.h>
 #include <uk/semaphore.h>
 #include <uk/thread.h>
 #endif
 
+#if LWIP_SOCKET && HAVE_LIBC
+#include <fcntl.h>
+#endif
+
 #define SYS_SEM_NULL   NULL
 #define SYS_MUTEX_NULL NULL
 #define SYS_MBOX_NULL  NULL
diff --git a/patches/0002-introduce-lwip_getsock_status.patch b/patches/0002-introduce-lwip_getsock_status.patch
new file mode 100644 (file)
index 0000000..45c9b76
--- /dev/null
@@ -0,0 +1,64 @@
+diff -urp lwip-2.0.3-orig/src/api/sockets.c src/api/sockets.c
+--- src/api/sockets.c  2018-03-20 13:07:37.161480805 +0100
++++ src/api/sockets.c  2018-03-19 18:01:08.206420575 +0100
+@@ -1290,6 +1290,46 @@ lwip_writev(int s, const struct iovec *i
+   return lwip_sendmsg(s, &msg, 0);\r
+ }\r
\r
++int lwip_getsock_status(int fd)\r
++{\r
++  int flags = 0;\r
++  struct lwip_sock *sock;\r
++\r
++  SYS_ARCH_DECL_PROTECT(lev);\r
++  SYS_ARCH_PROTECT(lev);\r
++  sock = tryget_socket(fd);\r
++  if (sock != NULL) {\r
++    void* lastdata = sock->lastdata;\r
++    s16_t rcvevent = sock->rcvevent;\r
++    u16_t sendevent = sock->sendevent;\r
++    u16_t errevent = sock->errevent;\r
++    SYS_ARCH_UNPROTECT(lev);\r
++\r
++    /* ... then examine it: */\r
++    /* See if netconn of this socket is ready for read */\r
++    if ((lastdata != NULL) || (rcvevent > 0)) {\r
++      flags |= LWIP_SOC_RD_READY;\r
++      LWIP_DEBUGF(SOCKETS_DEBUG, ("%s: lwip_fd=%d ready for reading\n",\r
++                                  __func__, fd));\r
++    }\r
++    /* See if netconn of this socket is ready for write */\r
++    if (sendevent != 0) {\r
++      flags |= LWIP_SOC_WR_READY;\r
++      LWIP_DEBUGF(SOCKETS_DEBUG, ("%s: lwip_fd=%d ready for writing\n",\r
++                                  __func__, fd));\r
++    }\r
++    /* See if netconn of this socket had an error */\r
++    if (errevent != 0) {\r
++      flags |= LWIP_SOC_EXCEPTION;\r
++      LWIP_DEBUGF(SOCKETS_DEBUG, ("%s: lwip_fd=%d ready for exception\n",\r
++                                  __func__, fd));\r
++    }\r
++  } else {\r
++    SYS_ARCH_UNPROTECT(lev);\r
++  }\r
++\r
++  return flags;\r
++}\r
+ /**\r
+  * Go through the readset and writeset lists and see which socket of the sockets\r
+  * set in the sets has events. On return, readset, writeset and exceptset have\r
+diff -urp src/include/lwip/sockets.h src/include/lwip/sockets.h
+--- src/include/lwip/sockets.h 2017-03-01 23:13:14.000000000 +0100
++++ src/include/lwip/sockets.h 2018-03-19 17:34:49.143047601 +0100
+@@ -419,6 +419,10 @@ typedef struct ip_mreq {
+ #define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &   (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))\r
+ #define FD_ZERO(p)    memset((void*)(p), 0, sizeof(*(p)))\r
\r
++#define LWIP_SOC_RD_READY  0x01\r
++#define LWIP_SOC_WR_READY  0x02\r
++#define LWIP_SOC_EXCEPTION 0x04\r
++\r
+ typedef struct fd_set\r
+ {\r
+   unsigned char fd_bits [(FD_SETSIZE+7)/8];\r