Ticket #1001: diff.txt

File diff.txt, 3.2 KB (added by ming, 11 years ago)

http://codereview.teluu.com/264193/show

Line 
1Index: pjlib/src/pj/ioqueue_winnt.c
2===================================================================
3--- pjlib/src/pj/ioqueue_winnt.c        (revision 3047)
4+++ pjlib/src/pj/ioqueue_winnt.c        (working copy)
5@@ -167,14 +167,27 @@
6 /*
7  * Process the socket when the overlapped accept() completed.
8  */
9-static void ioqueue_on_accept_complete(ioqueue_accept_rec *accept_overlapped)
10+static void ioqueue_on_accept_complete(pj_ioqueue_key_t *key,
11+                                       ioqueue_accept_rec *accept_overlapped)
12 {
13     struct sockaddr *local;
14     struct sockaddr *remote;
15     int locallen, remotelen;
16+    pj_status_t status;
17 
18     PJ_CHECK_STACK();
19 
20+    /* On WinXP or later, use SO_UPDATE_ACCEPT_CONTEXT so that socket
21+     * addresses can be obtained with getsockname() and getpeername().
22+     */
23+    status = setsockopt(accept_overlapped->newsock, SOL_SOCKET,
24+                        SO_UPDATE_ACCEPT_CONTEXT,
25+                        (char*)&key->hnd,
26+                        sizeof(SOCKET));
27+    /* SO_UPDATE_ACCEPT_CONTEXT is for WinXP or later.
28+     * So ignore the error status.
29+     */
30+
31     /* Operation complete immediately. */
32     if (accept_overlapped->addrlen) {
33        GetAcceptExSockaddrs( accept_overlapped->accept_buf,
34@@ -706,7 +719,7 @@
35 #if PJ_HAS_TCP
36        case PJ_IOQUEUE_OP_ACCEPT:
37            /* special case for accept. */
38-           ioqueue_on_accept_complete((ioqueue_accept_rec*)pOv);
39+           ioqueue_on_accept_complete(key, (ioqueue_accept_rec*)pOv);
40             if (key->cb.on_accept_complete) {
41                 ioqueue_accept_rec *accept_rec = (ioqueue_accept_rec*)pOv;
42                pj_status_t status = PJ_SUCCESS;
43@@ -1240,16 +1253,6 @@
44     if (status != PJ_SUCCESS)
45        return status;
46 
47-    /* On WinXP or later, use SO_UPDATE_ACCEPT_CONTEXT so that socket
48-     * addresses can be obtained with getsockname() and getpeername().
49-     */
50-    status = setsockopt(op_key_rec->accept.newsock, SOL_SOCKET,
51-                        SO_UPDATE_ACCEPT_CONTEXT,
52-                        (char*)&key->hnd, sizeof(SOCKET));
53-    /* SO_UPDATE_ACCEPT_CONTEXT is for WinXP or later.
54-     * So ignore the error status.
55-     */
56-
57     op_key_rec->accept.operation = PJ_IOQUEUE_OP_ACCEPT;
58     op_key_rec->accept.addrlen = addrlen;
59     op_key_rec->accept.local = local;
60@@ -1265,7 +1268,7 @@
61                   &op_key_rec->accept.overlapped );
62 
63     if (rc == TRUE) {
64-       ioqueue_on_accept_complete(&op_key_rec->accept);
65+       ioqueue_on_accept_complete(key, &op_key_rec->accept);
66        return PJ_SUCCESS;
67     } else {
68        DWORD dwStatus = WSAGetLastError();
69Index: pjlib/src/pjlib-test/ioq_tcp.c
70===================================================================
71--- pjlib/src/pjlib-test/ioq_tcp.c      (revision 3047)
72+++ pjlib/src/pjlib-test/ioq_tcp.c      (working copy)
73@@ -97,6 +97,15 @@
74                          "invalid socket and status is %d", status));
75        }
76     } else {
77+        pj_sockaddr addr;
78+        int client_addr_len;
79+
80+        client_addr_len = sizeof(addr);
81+        status = pj_sock_getsockname(sock, &addr, &client_addr_len);
82+        if (status != PJ_SUCCESS) {
83+            app_perror("...ERROR in pj_sock_getsockname()", status);
84+        }
85+
86        callback_accept_key = key;
87        callback_accept_op = op_key;
88        callback_accept_status = status;