From 2b228d36e3852f3a857ec2c73c056ca3a8f90025 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sat, 19 Nov 2005 13:19:28 +0000 Subject: Added PJ_IOQUEUE_ALWAYS_ASYNC flag git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@55 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/ioqueue_winnt.c | 92 +++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 40 deletions(-) (limited to 'pjlib/src/pj/ioqueue_winnt.c') diff --git a/pjlib/src/pj/ioqueue_winnt.c b/pjlib/src/pj/ioqueue_winnt.c index 65aaf2e9..828b568e 100644 --- a/pjlib/src/pj/ioqueue_winnt.c +++ b/pjlib/src/pj/ioqueue_winnt.c @@ -529,7 +529,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_recv( pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, void *buffer, pj_ssize_t *length, - unsigned flags ) + pj_uint32_t flags ) { /* * Ideally we should just call pj_ioqueue_recvfrom() with NULL addr and @@ -553,19 +553,23 @@ PJ_DEF(pj_status_t) pj_ioqueue_recv( pj_ioqueue_key_t *key, /* Try non-overlapped received first to see if data is * immediately available. */ - rc = WSARecv((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, - &bytesRead, &dwFlags, NULL, NULL); - if (rc == 0) { - *length = bytesRead; - return PJ_SUCCESS; - } else { - DWORD dwError = WSAGetLastError(); - if (dwError != WSAEWOULDBLOCK) { - *length = -1; - return PJ_RETURN_OS_ERROR(dwError); - } + if ((flags & PJ_IOQUEUE_ALWAYS_ASYNC) == 0) { + rc = WSARecv((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, + &bytesRead, &dwFlags, NULL, NULL); + if (rc == 0) { + *length = bytesRead; + return PJ_SUCCESS; + } else { + DWORD dwError = WSAGetLastError(); + if (dwError != WSAEWOULDBLOCK) { + *length = -1; + return PJ_RETURN_OS_ERROR(dwError); + } + } } + dwFlags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); + /* * No immediate data available. * Register overlapped Recv() operation. @@ -598,7 +602,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, void *buffer, pj_ssize_t *length, - unsigned flags, + pj_uint32_t flags, pj_sockaddr_t *addr, int *addrlen) { @@ -619,19 +623,23 @@ PJ_DEF(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_key_t *key, /* Try non-overlapped received first to see if data is * immediately available. */ - rc = WSARecvFrom((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, - &bytesRead, &dwFlags, addr, addrlen, NULL, NULL); - if (rc == 0) { - *length = bytesRead; - return PJ_SUCCESS; - } else { - DWORD dwError = WSAGetLastError(); - if (dwError != WSAEWOULDBLOCK) { - *length = -1; - return PJ_RETURN_OS_ERROR(dwError); - } + if ((flags & PJ_IOQUEUE_ALWAYS_ASYNC) == 0) { + rc = WSARecvFrom((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, + &bytesRead, &dwFlags, addr, addrlen, NULL, NULL); + if (rc == 0) { + *length = bytesRead; + return PJ_SUCCESS; + } else { + DWORD dwError = WSAGetLastError(); + if (dwError != WSAEWOULDBLOCK) { + *length = -1; + return PJ_RETURN_OS_ERROR(dwError); + } + } } + dwFlags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); + /* * No immediate data available. * Register overlapped Recv() operation. @@ -664,7 +672,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_send( pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, const void *data, pj_ssize_t *length, - unsigned flags ) + pj_uint32_t flags ) { return pj_ioqueue_sendto(key, op_key, data, length, flags, NULL, 0); } @@ -679,7 +687,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_sendto( pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, const void *data, pj_ssize_t *length, - unsigned flags, + pj_uint32_t flags, const pj_sockaddr_t *addr, int addrlen) { @@ -693,28 +701,32 @@ PJ_DEF(pj_status_t) pj_ioqueue_sendto( pj_ioqueue_key_t *key, op_key_rec = (union operation_key*)op_key->internal__; - dwFlags = flags; - /* * First try blocking write. */ op_key_rec->overlapped.wsabuf.buf = (void*)data; op_key_rec->overlapped.wsabuf.len = *length; - rc = WSASendTo((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, - &bytesWritten, dwFlags, addr, addrlen, - NULL, NULL); - if (rc == 0) { - *length = bytesWritten; - return PJ_SUCCESS; - } else { - DWORD dwStatus = WSAGetLastError(); - if (dwStatus != WSAEWOULDBLOCK) { - *length = -1; - return PJ_RETURN_OS_ERROR(dwStatus); - } + dwFlags = flags; + + if ((flags & PJ_IOQUEUE_ALWAYS_ASYNC) == 0) { + rc = WSASendTo((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, + &bytesWritten, dwFlags, addr, addrlen, + NULL, NULL); + if (rc == 0) { + *length = bytesWritten; + return PJ_SUCCESS; + } else { + DWORD dwStatus = WSAGetLastError(); + if (dwStatus != WSAEWOULDBLOCK) { + *length = -1; + return PJ_RETURN_OS_ERROR(dwStatus); + } + } } + dwFlags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); + /* * Data can't be sent immediately. * Schedule asynchronous WSASend(). -- cgit v1.2.3