From 3c8d3b370e33627a0a08a3bcfceaf9709e4a3991 Mon Sep 17 00:00:00 2001 From: Riza Sulistyo Date: Fri, 5 Apr 2013 03:02:19 +0000 Subject: 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 --- pjlib/include/pj/activesock.h | 27 ++++++++++++++++++++++++++- pjlib/include/pj/errno.h | 5 +++++ pjlib/src/pj/activesock.c | 28 ++++++++++++++++++++++++---- pjlib/src/pj/errno.c | 3 ++- 4 files changed, 57 insertions(+), 6 deletions(-) (limited to 'pjlib') 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. @@ -149,6 +150,30 @@ typedef struct pj_activesock_cb const pj_sockaddr_t *src_addr, 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 */ -- cgit v1.2.3