]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
Implement accept(), listen(), and connect() for libvfscore
authorSharan Santhanam <sharan.santhanam@neclab.eu>
Wed, 13 Jun 2018 00:21:22 +0000 (02:21 +0200)
committerSimon Kuenzer <simon.kuenzer@neclab.eu>
Fri, 15 Jun 2018 01:21:07 +0000 (03:21 +0200)
Signed-off-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
socket_glue.c

index c323ffc63779c7b91217dad6e55a00a1464d60bf..e80fb73109e2a76160edbca4b3089417f2fe1a07 100644 (file)
@@ -134,7 +134,42 @@ LWIP_SOCKET_CLEANUP:
 int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
 {
        int ret = 0;
+       struct sock_net_file *file;
+       int sock_fd, vfs_fd;
+       file = sock_net_file_get(s);
+       if(PTRISERR(file)) {
+               uk_printd(DLVL_ERR, "failed to accept incomingi connection \n");
+               ret = -1;
+               /* Setting the errno */
+               SOCK_NET_SET_ERRNO(PTR2ERR(file));
+               goto EXIT;
+       }
+
+       /* Accept an incoming connection */
+       sock_fd = lwip_accept(file->sock_fd, addr, addrlen);
+       if(0 > sock_fd) {
+               uk_printd(DLVL_ERR, "failed to accept incoming connection \n");
+               ret = -1;
+               goto EXIT;
+       }
+
+       /* Allocate the file descriptor for the accepted connection */
+       vfs_fd = sock_fd_alloc(&sock_net_fops, sock_fd);
+       if(0 > vfs_fd) {
+               uk_printd(DLVL_ERR, "failed to allocate descriptor for the"
+                       "accepted connection \n");
+               ret = -1;
+               /* Setting the errno */
+               SOCK_NET_SET_ERRNO(vfs_fd);
+               goto LWIP_SOCKET_CLEANUP;
+       }
+       ret = vfs_fd;
+EXIT:
        return ret;
+
+LWIP_SOCKET_CLEANUP:
+       lwip_close(sock_fd);
+       goto EXIT;
 }
 
 int bind(int s, const struct sockaddr *name, socklen_t namelen)
@@ -195,12 +230,32 @@ int setsockopt (int s, int level, int optname, const void *optval,
 int connect(int s, const struct sockaddr *name, socklen_t namelen)
 {
        int ret = 0;
+       struct sock_net_file *file = NULL;
+       file = sock_net_file_get(s);
+       if(PTRISERR(file)) {
+               uk_printd(DLVL_ERR, "failed to identify the socket descriptor \n");
+               ret = -1;
+               SOCK_NET_SET_ERRNO(PTR2ERR(file));
+               goto EXIT;
+       }
+       ret = lwip_connect(file->sock_fd, name, namelen);
+EXIT:
        return ret;
 }
 
 int listen(int s, int backlog)
 {
        int ret = 0;
+       struct sock_net_file *file = NULL;
+       file = sock_net_file_get(s);
+       if(PTRISERR(file)) {
+               uk_printd(DLVL_ERR, "failed to identify the socket descriptor \n");
+               ret = -1;
+               SOCK_NET_SET_ERRNO(PTR2ERR(file));
+               goto EXIT;
+       }
+       ret = lwip_listen(file->sock_fd, backlog);
+EXIT:
        return ret;
 }