MCPcopy Create free account
hub / github.com/Tencent/UnLua / socket_connect

Function socket_connect

Plugins/UnLuaExtensions/LuaSocket/Source/src/usocket.cpp:160–177  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Connects or returns error message \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

158* Connects or returns error message
159\*-------------------------------------------------------------------------*/
160int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) {
161 int err;
162 /* avoid calling on closed sockets */
163 if (*ps == SOCKET_INVALID) return IO_CLOSED;
164 /* call connect until done or failed without being interrupted */
165 do if (connect(*ps, addr, len) == 0) return IO_DONE;
166 while ((err = errno) == EINTR);
167 /* if connection failed immediately, return error code */
168 if (err != EINPROGRESS && err != EAGAIN) return err;
169 /* zero timeout case optimization */
170 if (timeout_iszero(tm)) return IO_TIMEOUT;
171 /* wait until we have the result of the connection attempt or timeout */
172 err = socket_waitfd(ps, WAITFD_C, tm);
173 if (err == IO_CLOSED) {
174 if (recv(*ps, (char *) &err, 0, 0) == 0) return IO_DONE;
175 else return errno;
176 } else return err;
177}
178
179/*-------------------------------------------------------------------------*\
180* Accept with timeout

Callers 4

inet_trydisconnectFunction · 0.70
inet_tryconnectFunction · 0.70
unixdgram_tryconnectFunction · 0.70
unixstream_tryconnectFunction · 0.70

Calls 1

socket_waitfdFunction · 0.70

Tested by

no test coverage detected