Misc (#1026): PJLIB does not return the correct error code when TCP connection fails on Linux
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3088 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/ioqueue_common_abs.c b/pjlib/src/pj/ioqueue_common_abs.c
index cccabc8..bcd4f6a 100644
--- a/pjlib/src/pj/ioqueue_common_abs.c
+++ b/pjlib/src/pj/ioqueue_common_abs.c
@@ -199,7 +199,7 @@
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP!=0
if (h->connecting) {
/* Completion of connect() operation */
- pj_ssize_t bytes_transfered;
+ pj_status_t status;
pj_bool_t has_lock;
/* Clear operation. */
@@ -226,13 +226,13 @@
* application will get error as soon as it tries to use
* the socket to send/receive.
*/
- bytes_transfered = 0;
+ status = PJ_SUCCESS;
} else {
- bytes_transfered = value;
+ status = PJ_STATUS_FROM_OS(value);
}
}
#elif defined(PJ_WIN32) && PJ_WIN32!=0
- bytes_transfered = 0; /* success */
+ status = PJ_SUCCESS; /* success */
#else
/* Excellent information in D.J. Bernstein page:
* http://cr.yp.to/docs/connect.html
@@ -245,12 +245,11 @@
* of suggestions from Douglas C. Schmidt and Ken Keys.
*/
{
- int gp_rc;
struct sockaddr_in addr;
- socklen_t addrlen = sizeof(addr);
+ int addrlen = sizeof(addr);
- gp_rc = getpeername(h->fd, (struct sockaddr*)&addr, &addrlen);
- bytes_transfered = (gp_rc < 0) ? gp_rc : -gp_rc;
+ status = pj_sock_getpeername(h->fd, (struct sockaddr*)&addr,
+ &addrlen);
}
#endif
@@ -269,7 +268,7 @@
/* Call callback. */
if (h->cb.on_connect_complete && !IS_CLOSING(h))
- (*h->cb.on_connect_complete)(h, bytes_transfered);
+ (*h->cb.on_connect_complete)(h, status);
/* Unlock if we still hold the lock */
if (has_lock) {