summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorRiza Sulistyo <riza@teluu.com>2013-04-05 03:02:19 +0000
committerRiza Sulistyo <riza@teluu.com>2013-04-05 03:02:19 +0000
commit3c8d3b370e33627a0a08a3bcfceaf9709e4a3991 (patch)
tree7e65b6d873106dd32e1809f9c59ee64bb5329a6c /pjlib
parentcebde64ea044c362999974b662dc3e58e0577778 (diff)
Re #1643: Code restructure+add callback to support symbian gui app
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4461 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/include/pj/activesock.h27
-rw-r--r--pjlib/include/pj/errno.h5
-rw-r--r--pjlib/src/pj/activesock.c28
-rw-r--r--pjlib/src/pj/errno.c3
4 files changed, 57 insertions, 6 deletions
diff --git a/pjlib/include/pj/activesock.h b/pjlib/include/pj/activesock.h
index 11fa6589..e1584719 100644
--- a/pjlib/include/pj/activesock.h
+++ b/pjlib/include/pj/activesock.h
@@ -132,7 +132,8 @@ typedef struct pj_activesock_cb
/**
* This callback is called when new connection arrives as the result
- * of pj_activesock_start_accept().
+ * of pj_activesock_start_accept(). If the status of accept operation is
+ * needed use on_accept_complete2 instead of this callback.
*
* @param asock The active socket.
* @param newsock The new incoming socket.
@@ -150,6 +151,30 @@ typedef struct pj_activesock_cb
int src_addr_len);
/**
+ * This callback is called when new connection arrives as the result
+ * of pj_activesock_start_accept().
+ *
+ * @param asock The active socket.
+ * @param newsock The new incoming socket.
+ * @param src_addr The source address of the connection.
+ * @param addr_len Length of the source address.
+ * @param status The status of the accept operation. This may contain
+ * non-PJ_SUCCESS for example when the TCP listener is in
+ * bad state for example on iOS platform after the
+ * application waking up from background.
+ *
+ * @return PJ_TRUE if further accept() is desired, and PJ_FALSE
+ * when application no longer wants to accept incoming
+ * connection. Application may destroy the active socket
+ * in the callback and return PJ_FALSE here.
+ */
+ pj_bool_t (*on_accept_complete2)(pj_activesock_t *asock,
+ pj_sock_t newsock,
+ const pj_sockaddr_t *src_addr,
+ int src_addr_len,
+ pj_status_t status);
+
+ /**
* This callback is called when pending connect operation has been
* completed.
*
diff --git a/pjlib/include/pj/errno.h b/pjlib/include/pj/errno.h
index e9e403ce..05008b10 100644
--- a/pjlib/include/pj/errno.h
+++ b/pjlib/include/pj/errno.h
@@ -427,6 +427,11 @@ PJ_DECL(pj_status_t) pj_register_strerror(pj_status_t start_code,
* Object no longer exists
*/
#define PJ_EGONE (PJ_ERRNO_START_STATUS + 23)/* 70023 */
+/**
+ * @hideinitializer
+ * Socket is stopped
+ */
+#define PJ_ESOCKETSTOP (PJ_ERRNO_START_STATUS + 24)/* 70024 */
/** @} */ /* pj_errnum */
diff --git a/pjlib/src/pj/activesock.c b/pjlib/src/pj/activesock.c
index 2c0cad55..bbe10676 100644
--- a/pjlib/src/pj/activesock.c
+++ b/pjlib/src/pj/activesock.c
@@ -843,6 +843,16 @@ static void ioqueue_on_accept_complete(pj_ioqueue_key_t *key,
PJ_LOG(3, ("", "Received %d consecutive errors: %d for the accept()"
" operation, stopping further ioqueue accepts.",
asock->err_counter, asock->last_err));
+
+ if ((status == PJ_STATUS_FROM_OS(OSERR_EWOULDBLOCK)) &&
+ (asock->cb.on_accept_complete2))
+ {
+ (*asock->cb.on_accept_complete2)(asock,
+ accept_op->new_sock,
+ &accept_op->rem_addr,
+ accept_op->rem_addr_len,
+ PJ_ESOCKETSTOP);
+ }
return;
}
} else {
@@ -850,13 +860,23 @@ static void ioqueue_on_accept_complete(pj_ioqueue_key_t *key,
asock->last_err = status;
}
- if (status==PJ_SUCCESS && asock->cb.on_accept_complete) {
+ if (status==PJ_SUCCESS && (asock->cb.on_accept_complete2 ||
+ asock->cb.on_accept_complete)) {
pj_bool_t ret;
/* Notify callback */
- ret = (*asock->cb.on_accept_complete)(asock, accept_op->new_sock,
- &accept_op->rem_addr,
- accept_op->rem_addr_len);
+ if (asock->cb.on_accept_complete2) {
+ ret = (*asock->cb.on_accept_complete2)(asock,
+ accept_op->new_sock,
+ &accept_op->rem_addr,
+ accept_op->rem_addr_len,
+ status);
+ } else {
+ ret = (*asock->cb.on_accept_complete)(asock,
+ accept_op->new_sock,
+ &accept_op->rem_addr,
+ accept_op->rem_addr_len);
+ }
/* If callback returns false, we have been destroyed! */
if (!ret)
diff --git a/pjlib/src/pj/errno.c b/pjlib/src/pj/errno.c
index 4726b33d..ae59f450 100644
--- a/pjlib/src/pj/errno.c
+++ b/pjlib/src/pj/errno.c
@@ -78,7 +78,8 @@ static const struct
PJ_BUILD_ERR(PJ_EIGNORED, "Ignored"),
PJ_BUILD_ERR(PJ_EIPV6NOTSUP, "IPv6 is not supported"),
PJ_BUILD_ERR(PJ_EAFNOTSUP, "Unsupported address family"),
- PJ_BUILD_ERR(PJ_EGONE, "Object no longer exists")
+ PJ_BUILD_ERR(PJ_EGONE, "Object no longer exists"),
+ PJ_BUILD_ERR(PJ_ESOCKETSTOP, "Socket is in bad state")
};
#endif /* PJ_HAS_ERROR_STRING */