From e3fea05c242744a56101e992a1e1601d4edaf458 Mon Sep 17 00:00:00 2001 From: Sangho Park Date: Mon, 1 Feb 2016 15:14:32 +0900 Subject: [PATCH] net_helper: use qemu_socket() instead of socket() * 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 --- tizen/src/util/net_helper.c | 55 +++---------------------------------- tizen/src/util/net_helper.h | 1 - 2 files changed, 4 insertions(+), 52 deletions(-) diff --git a/tizen/src/util/net_helper.c b/tizen/src/util/net_helper.c index 82d0382082..2b8d902fc6 100644 --- a/tizen/src/util/net_helper.c +++ b/tizen/src/util/net_helper.c @@ -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 - -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; } diff --git a/tizen/src/util/net_helper.h b/tizen/src/util/net_helper.h index be0651f7ef..dd3cc9ff6b 100644 --- a/tizen/src/util/net_helper.h +++ b/tizen/src/util/net_helper.h @@ -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); -- 2.34.1