change get_peer_addresses to use context wsi latency
authorAndy Green <andy.green@linaro.org>
Wed, 30 Jan 2013 00:12:20 +0000 (08:12 +0800)
committerAndy Green <andy.green@linaro.org>
Wed, 30 Jan 2013 00:49:13 +0000 (08:49 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/libwebsockets.c
lib/libwebsockets.h
libwebsockets-api-doc.html
test-server/test-ping.c
test-server/test-server.c

index 38fc098..1b406e6 100644 (file)
@@ -391,6 +391,8 @@ libwebsockets_hangup_on_client(struct libwebsocket_context *context, int fd)
 
 /**
  * libwebsockets_get_peer_addresses() - Get client address information
+ * @context:   Libwebsockets context
+ * @wsi:       Local struct libwebsocket associated with
  * @fd:                Connection socket descriptor
  * @name:      Buffer to take client address name
  * @name_len:  Length of client address name buffer
@@ -404,7 +406,8 @@ libwebsockets_hangup_on_client(struct libwebsocket_context *context, int fd)
  */
 
 void
-libwebsockets_get_peer_addresses(int fd, char *name, int name_len,
+libwebsockets_get_peer_addresses(struct libwebsocket_context *context,
+       struct libwebsocket *wsi, int fd, char *name, int name_len,
                                        char *rip, int rip_len)
 {
        unsigned int len;
@@ -414,6 +417,7 @@ libwebsockets_get_peer_addresses(int fd, char *name, int name_len,
        char ip[128];
        unsigned char *p;
        int n;
+       int ret = -1;
 #ifdef AF_LOCAL
     struct sockaddr_un *un;
 #endif
@@ -421,17 +425,19 @@ libwebsockets_get_peer_addresses(int fd, char *name, int name_len,
        rip[0] = '\0';
        name[0] = '\0';
 
+       lws_latency_pre(context, wsi);
+
        len = sizeof sin;
        if (getpeername(fd, (struct sockaddr *) &sin, &len) < 0) {
                perror("getpeername");
-               return;
+               goto bail;
        }
 
        host = gethostbyaddr((char *) &sin.sin_addr, sizeof sin.sin_addr,
                                                                       AF_INET);
        if (host == NULL) {
                perror("gethostbyaddr");
-               return;
+               goto bail;
        }
 
        strncpy(name, host->h_name, name_len);
@@ -439,7 +445,7 @@ libwebsockets_get_peer_addresses(int fd, char *name, int name_len,
 
        host1 = gethostbyname(host->h_name);
        if (host1 == NULL)
-               return;
+               goto bail;
        p = (unsigned char *)host1;
        n = 0;
        while (p != NULL) {
@@ -466,6 +472,10 @@ libwebsockets_get_peer_addresses(int fd, char *name, int name_len,
                strncpy(rip, ip, rip_len);
                rip[rip_len - 1] = '\0';
        }
+
+       ret = 0;
+bail:
+       lws_latency(context, wsi, "libwebsockets_get_peer_addresses", ret, 1);
 }
 
 int libwebsockets_get_random(struct libwebsocket_context *context,
index 113e9d5..cef5c80 100644 (file)
@@ -856,7 +856,8 @@ libwebsocket_canonical_hostname(struct libwebsocket_context *context);
 
 
 LWS_EXTERN void
-libwebsockets_get_peer_addresses(int fd, char *name, int name_len,
+libwebsockets_get_peer_addresses(struct libwebsocket_context *context,
+               struct libwebsocket *wsi, int fd, char *name, int name_len,
                                        char *rip, int rip_len);
 
 LWS_EXTERN void
index 402c36d..c67692a 100644 (file)
@@ -101,13 +101,19 @@ This function creates a connection to a remote server
 <h2>libwebsockets_get_peer_addresses - Get client address information</h2>
 <i>void</i>
 <b>libwebsockets_get_peer_addresses</b>
-(<i>int</i> <b>fd</b>,
+(<i>struct libwebsocket_context *</i> <b>context</b>,
+<i>struct libwebsocket *</i> <b>wsi</b>,
+<i>int</i> <b>fd</b>,
 <i>char *</i> <b>name</b>,
 <i>int</i> <b>name_len</b>,
 <i>char *</i> <b>rip</b>,
 <i>int</i> <b>rip_len</b>)
 <h3>Arguments</h3>
 <dl>
+<dt><b>context</b>
+<dd>Libwebsockets context
+<dt><b>wsi</b>
+<dd>Local struct libwebsocket associated with
 <dt><b>fd</b>
 <dd>Connection socket descriptor
 <dt><b>name</b>
index 773b792..ec2df1f 100644 (file)
@@ -434,7 +434,7 @@ int main(int argc, char **argv)
                }
        }
 
-       libwebsockets_get_peer_addresses(
+       libwebsockets_get_peer_addresses(context, ping_wsi[0],
                        libwebsocket_get_socket_fd(ping_wsi[0]),
                                    peer_name, sizeof peer_name, ip, sizeof ip);
 
index d54c371..5d06fa0 100644 (file)
@@ -138,7 +138,7 @@ static int callback_http(struct libwebsocket_context *context,
 
        case LWS_CALLBACK_FILTER_NETWORK_CONNECTION:
 #if 0
-               libwebsockets_get_peer_addresses((int)(long)user, client_name,
+               libwebsockets_get_peer_addresses(context, wsi, (int)(long)user, client_name,
                             sizeof(client_name), client_ip, sizeof(client_ip));
 
                fprintf(stderr, "Received network connect from %s (%s)\n",