[Title] change sdb connection issue when network is unavaliable
authoryoonki.park <yoonki.park@samsung.com>
Wed, 25 Apr 2012 07:07:15 +0000 (16:07 +0900)
committeryoonki.park <yoonki.park@samsung.com>
Wed, 25 Apr 2012 07:21:10 +0000 (16:21 +0900)
[Type]
[Module]
[Priority]
[CQ#]
[Redmine#] 5125
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: I9223e0fc202e7c8c5f53be051c5112a8b6ba4933

tizen/src/sdb.c
tizen/src/sdb.h

index 434c8bdd3b63ab339751527d4b352ff5d2690b8f..56d2e74efa07371c153d1a74ad08dff95c540266 100644 (file)
@@ -325,35 +325,55 @@ void sdb_setup(void)
        }
 }
 
-void notify_sdb_daemon_start(void)
+int sdb_loopback_client(int port, int type)
 {
-       int s;
+    struct sockaddr_in addr;
+    int s;
+
+    memset(&addr, 0, sizeof(addr));
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(port);
+    addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+    s = socket(AF_INET, type, 0);
+    if(s < 0) return -1;
+
+    if(connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+        close(s);
+        return -1;
+    }
+
+    return s;
+
+}
+
+void notify_sdb_daemon_start(void) {
+    int s;
     /* 
      * send a simple message to the SDB host server to tell it we just started.
-        * it should be listening on port 26099.
-        */
-    do
-       {
-               char tmp[32] = {0};
-
-               s = tcp_socket_outgoing("127.0.0.1", SDB_HOST_PORT);
-               if (s < 0) {
-                       INFO("can't create socket to talk to the SDB server \n");
-                       INFO("This emulator will be scaned by the SDB server \n");
-                       break;
-               }
+     * it should be listening on port 26099.
+     */
+    do {
+        char tmp[32] = { 0 };
+
+        // when connecting to loopback:26099, do not use tcp_socket_outgoing function
+        // tcp_socket_outgoing may occur "dns name service not known" in case of network unavaliable status.
+        s = sdb_loopback_client(SDB_HOST_PORT, SOCK_STREAM);
+        if (s < 0) {
+            INFO("can't create socket to talk to the SDB server \n");
+            INFO("This emulator will be scaned by the SDB server \n");
+            break;
+        }
+
+        /* length is hex: 0x13 = 19 */
+        sprintf(tmp, "0013host:emulator:%d", tizen_base_port + 1);
 
-               /* length is hex: 0x13 = 19 */
-               sprintf(tmp,"0013host:emulator:%d", tizen_base_port +1);
-               
-        if(socket_send(s, tmp, 30) < 0) {
+        if (socket_send(s, tmp, 30) < 0) {
             ERR( "message sending to sdb server error!\n");
         }
 
-       }
-       while (0);
+    } while (0);
 
-       if (s >= 0)
-               socket_close(s);
-   
+    if (s >= 0)
+        socket_close(s);
 }
index 49618da561c3d6e9fe45d344991c1db1b83bf89a..b30951611e7161b5696c3eb43bea985cca349bf6 100644 (file)
@@ -110,3 +110,4 @@ int inet_strtoip(const char*  str, uint32_t  *ip);
 int socket_send(int fd, const void*  buf, int  buflen);
 void socket_close(int fd);
 void notify_sdb_daemon_start(void);
+int sdb_loopback_client(int port, int type);