net_helper: use qemu_socket() instead of socket()
authorSangho Park <sangho.p@samsung.com>
Mon, 1 Feb 2016 06:14:32 +0000 (15:14 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 11 Feb 2016 04:53:46 +0000 (13:53 +0900)
* Change socket() to qemu_socket()
** qemu_socket() turns on SOCK_CLOEXEC option.
* Remove unused functions, socket_close() and socket_close_handler()

Change-Id: I8878bd50b2a6a78680583a5922c597378c67eea3
Signed-off-by: Sangho Park <sangho.p@samsung.com>
tizen/src/util/net_helper.c
tizen/src/util/net_helper.h

index 82d0382082172106c46b07be2815b5cdd39e5864..2b8d902fc6137f94abfdda835f7df5e4a2255560 100644 (file)
@@ -50,53 +50,6 @@ DECLARE_DEBUG_CHANNEL(sdb);
 
 int emul_vm_base_socket;
 static bool sdb_daemon_is_initialized = false;
-#ifdef _WIN32
-#include "qemu/main-loop.h"
-
-static void socket_close_handler( void*  _fd )
-{
-    int   fd = (int)(uintptr_t)_fd;
-    int   ret;
-    char  buff[BUF_SIZE];
-
-    /* we want to drain the read side of the socket before closing it */
-    do {
-        ret = recv( fd, buff, sizeof(buff), 0 );
-    } while (ret < 0 && WSAGetLastError() == WSAEINTR);
-
-    if (ret < 0 && WSAGetLastError() == EWOULDBLOCK)
-        return;
-
-    qemu_set_fd_handler( fd, NULL, NULL, NULL );
-    closesocket( fd );
-}
-
-void socket_close( int  fd )
-{
-    int  old_errno = errno;
-
-    shutdown( fd, SD_BOTH );
-    /* we want to drain the socket before closing it */
-    qemu_set_fd_handler( fd, socket_close_handler, NULL, (void*)(uintptr_t)fd );
-
-    errno = old_errno;
-}
-
-#else /* !_WIN32 */
-
-#include <unistd.h>
-
-void socket_close( int  fd )
-{
-    int  old_errno = errno;
-
-    shutdown( fd, SHUT_RDWR );
-    close( fd );
-
-    errno = old_errno;
-}
-
-#endif /* !_WIN32 */
 
 int inet_strtoip(const char*  str, uint32_t  *ip)
 {
@@ -276,7 +229,7 @@ static void send_to_sdb_client(SDB_Client* client, int state)
     int serial_len = 0;
     char buf[BUF_SIZE];
 
-    if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1){
+    if ((s = qemu_socket(AF_INET, SOCK_STREAM, 0)) == -1){
           LOG_INFO("socket creation error! %d\n", errno);
           return;
     }
@@ -290,7 +243,7 @@ static void send_to_sdb_client(SDB_Client* client, int state)
     if (connect(s, (struct sockaddr*)&sock_addr, slen) == -1) {
         LOG_INFO("connect error! remove this client.\n");
         remove_sdb_client(client);
-        close(s);
+        closesocket(s);
         return;
     }
 
@@ -309,7 +262,7 @@ static void send_to_sdb_client(SDB_Client* client, int state)
         remove_sdb_client(client);
     }
 
-    close(s);
+    closesocket(s);
 }
 
 void notify_all_sdb_clients(int state)
@@ -535,7 +488,7 @@ static int create_UDP_server(SDB_Noti_Server *server, int port)
     struct sockaddr_in server_addr;
     int opt = 1;
 
-    if ((server->server_fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+    if ((server->server_fd = qemu_socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
         LOG_INFO("create listen socket error:%d\n", errno);
         return -1;
     }
index be0651f7efe4ef8261ec7b2d5b5dd198d529d820..dd3cc9ff6bd5c564908c3e5fbd0ce69205732e16 100644 (file)
@@ -65,7 +65,6 @@
 void init_sdb_and_vm_base_port(void);
 int inet_strtoip(const char*  str, uint32_t  *ip);
 int socket_send(int fd, const void*  buf, int  buflen);
-void socket_close(int fd);
 int check_port_bind_listen(uint32_t port);
 bool is_sdb_daemon_initialized(void);