- Timestamp:
- May 8, 2013 12:32:54 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mangling.h
r45400 r45948 1445 1445 # define RTTarOpen RT_MANGLER(RTTarOpen) 1446 1446 # define RTTarSeekNextFile RT_MANGLER(RTTarSeekNextFile) 1447 # define RTTcpClientCancelConnect RT_MANGLER(RTTcpClientCancelConnect) 1447 1448 # define RTTcpClientClose RT_MANGLER(RTTcpClientClose) 1448 1449 # define RTTcpClientCloseEx RT_MANGLER(RTTcpClientCloseEx) 1449 1450 # define RTTcpClientConnect RT_MANGLER(RTTcpClientConnect) 1451 # define RTTcpClientConnectEx RT_MANGLER(RTTcpClientConnectEx) 1450 1452 # define RTTcpFlush RT_MANGLER(RTTcpFlush) 1451 1453 # define RTTcpGetLocalAddress RT_MANGLER(RTTcpGetLocalAddress) -
trunk/include/iprt/tcp.h
r33540 r45948 171 171 RTR3DECL(int) RTTcpClientConnect(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock); 172 172 173 /** Opaque pointer used by RTTcpClientConnectEx and RTTcpClientCancelConnect. */ 174 typedef struct RTTCPCLIENTCONNECTCANCEL *PRTTCPCLIENTCONNECTCANCEL; 175 176 /** 177 * Connect (as a client) to a TCP Server, extended version. 178 * 179 * @returns iprt status code. 180 * @param pszAddress The address to connect to. 181 * @param uPort The port to connect to. 182 * @param pSock Where to store the handle to the established connection. 183 * @param ppCancelCookie Where to store information for canceling the 184 * operation (from a different thread). Optional. 185 * 186 * The pointer _must_ be initialized to NULL before a 187 * series of connection attempts begins, i.e. at a time 188 * where there will be no RTTcpClientCancelConnect 189 * calls racing access. RTTcpClientCancelConnect will 190 * set it to a special non-NULL value that causes the 191 * current or/and next connect call to fail. 192 * 193 * @sa RTTcpClientCancelConnect 194 */ 195 RTR3DECL(int) RTTcpClientConnectEx(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock, 196 PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie); 197 198 /** 199 * Cancels a RTTcpClientConnectEx call on a different thread. 200 * 201 * @returns iprt status code. 202 * @param ppCancelCookie The address of the cookie pointer shared with the 203 * connect call. 204 */ 205 RTR3DECL(int) RTTcpClientCancelConnect(PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie); 206 173 207 /** 174 208 * Close a socket returned by RTTcpClientConnect(). -
trunk/src/VBox/Runtime/r3/tcp.cpp
r44528 r45948 806 806 RTR3DECL(int) RTTcpClientConnect(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock) 807 807 { 808 return RTTcpClientConnectEx(pszAddress, uPort, pSock, NULL); 809 } 810 811 812 RTR3DECL(int) RTTcpClientConnectEx(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock, 813 PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie) 814 { 808 815 /* 809 816 * Validate input. … … 811 818 AssertReturn(uPort > 0, VERR_INVALID_PARAMETER); 812 819 AssertPtrReturn(pszAddress, VERR_INVALID_POINTER); 820 AssertPtrNullReturn(ppCancelCookie, VERR_INVALID_POINTER); 813 821 814 822 /* … … 829 837 RTSocketSetInheritance(Sock, false /*fInheritable*/); 830 838 831 rc = rtSocketConnect(Sock, &Addr); 839 if (!ppCancelCookie) 840 rc = rtSocketConnect(Sock, &Addr); 841 else 842 { 843 RTSocketRetain(Sock); 844 if (ASMAtomicCmpXchgPtr(ppCancelCookie, (PRTTCPCLIENTCONNECTCANCEL)Sock, NULL)) 845 { 846 rc = rtSocketConnect(Sock, &Addr); 847 if (ASMAtomicCmpXchgPtr(ppCancelCookie, NULL, (PRTTCPCLIENTCONNECTCANCEL)Sock)) 848 RTSocketRelease(Sock); 849 else 850 rc = VERR_CANCELLED; 851 } 852 else 853 { 854 RTSocketRelease(Sock); 855 rc = VERR_CANCELLED; 856 } 857 } 832 858 if (RT_SUCCESS(rc)) 833 859 { … … 838 864 rtTcpClose(Sock, "RTTcpClientConnect", false /*fTryGracefulShutdown*/); 839 865 } 866 if (ppCancelCookie) 867 *ppCancelCookie = NULL; 840 868 return rc; 869 } 870 871 872 RTR3DECL(int) RTTcpClientCancelConnect(PRTTCPCLIENTCONNECTCANCEL volatile *ppCancelCookie) 873 { 874 AssertPtrReturn(ppCancelCookie, VERR_INVALID_POINTER); 875 876 AssertCompile(NIL_RTSOCKET == NULL); 877 RTSOCKET hSock = (RTSOCKET)ASMAtomicXchgPtr((void * volatile *)ppCancelCookie, (void *)(uintptr_t)0xdead9999); 878 if (hSock != NIL_RTSOCKET) 879 { 880 int rc = rtTcpClose(hSock, "RTTcpClientCancelConnect", false /*fTryGracefulShutdown*/); 881 AssertRCReturn(rc, rc); 882 } 883 884 return VINF_SUCCESS; 841 885 } 842 886
Note:
See TracChangeset
for help on using the changeset viewer.