]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
Implement read and write operation for sockets with libvfscore
authorSharan Santhanam <sharan.santhanam@neclab.eu>
Wed, 13 Jun 2018 00:23:31 +0000 (02:23 +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 e80fb73109e2a76160edbca4b3089417f2fe1a07..5fdfb7e98ac1ac8025f32424a04afffdf70aabad 100644 (file)
@@ -81,6 +81,12 @@ static ssize_t sock_net_write(struct vfscore_file *vfscore_file, const void *buf
                             size_t count)
 {
        int ret = 0;
+       struct sock_net_file *file = NULL;
+       file = __containerof(vfscore_file, struct sock_net_file,
+                               vfscore_file);
+       uk_printd(DLVL_EXTRA, NET_LIB_NAME": write %d (%x):%s\n",
+                       file->vfscore_file.fd, file->sock_fd, (char *) buf);
+       ret = lwip_write(file->sock_fd, buf, count);
        return ret;
 }
 
@@ -88,6 +94,12 @@ static ssize_t sock_net_read(struct vfscore_file *vfscore_file, void *buf,
                            size_t count)
 {
        int ret = 0;
+       struct sock_net_file *file = NULL;
+       file = __containerof(vfscore_file, struct sock_net_file,
+                               vfscore_file);
+       uk_printd(DLVL_EXTRA, NET_LIB_NAME": write %d (%x):%s\n",
+                       file->vfscore_file.fd, file->sock_fd, (char *) buf);
+       ret = lwip_read(file->sock_fd, buf, count);
        return ret;
 }
 
@@ -262,6 +274,16 @@ EXIT:
 int recv(int s, void *mem, size_t len, int flags)
 {
        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_recv(file->sock_fd, mem, len, flags);
+EXIT:
        return ret;
 }
 
@@ -269,18 +291,48 @@ int recvfrom(int s, void *mem, size_t len, int flags,
                      struct sockaddr *from, socklen_t *fromlen)
 {
        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_recvfrom(file->sock_fd, mem, len, flags, from, fromlen);
+EXIT:
        return ret;
 }
 
 int send(int s, const void *dataptr, size_t size, int flags)
 {
        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_send(file->sock_fd, dataptr, size, flags);
+EXIT:
        return ret;
 }
 
 int sendmsg(int s, const struct msghdr *message, int flags)
 {
        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_sendmsg(file->sock_fd, message, flags);
+EXIT:
        return ret;
 }
 
@@ -288,6 +340,16 @@ int sendto(int s, const void *dataptr, size_t size, int flags,
                    const struct sockaddr *to, socklen_t tolen)
 {
        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_sendto(file->sock_fd, dataptr, size, flags, to, tolen);
+EXIT:
        return ret;
 }