Changeset 55


Ignore:
Timestamp:
Nov 19, 2005 1:19:28 PM (18 years ago)
Author:
bennylp
Message:

Added PJ_IOQUEUE_ALWAYS_ASYNC flag

Location:
pjproject/trunk/pjlib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/ioqueue.h

    r51 r55  
    234234#   define PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL     (16) 
    235235#endif 
     236 
     237/** 
     238 * When this flag is specified in ioqueue's recv() or send() operations, 
     239 * the ioqueue will always mark the operation as asynchronous. 
     240 */ 
     241#define PJ_IOQUEUE_ALWAYS_ASYNC     ((pj_uint32_t)1 << (pj_uint32_t)31) 
    236242 
    237243/** 
     
    506512 *                  caller's stack and doesn't have to remain valid for the 
    507513 *                  duration of pending operation. 
    508  * @param flags     Recv flag. 
     514 * @param flags     Recv flag. If flags has PJ_IOQUEUE_ALWAYS_ASYNC then 
     515 *                  the function will never return PJ_SUCCESS. 
    509516 * 
    510517 * @return 
     
    519526                                      void *buffer, 
    520527                                      pj_ssize_t *length, 
    521                                       unsigned flags ); 
     528                                      pj_uint32_t flags ); 
    522529 
    523530/** 
     
    543550 *                  caller's stack and doesn't have to remain valid for the 
    544551 *                  duration of pending operation. 
    545  * @param flags     Recv flag. 
     552 * @param flags     Recv flag. If flags has PJ_IOQUEUE_ALWAYS_ASYNC then 
     553 *                  the function will never return PJ_SUCCESS. 
    546554 * @param addr      Optional Pointer to buffer to receive the address. 
    547555 * @param addrlen   On input, specifies the length of the address buffer. 
     
    561569                                          void *buffer, 
    562570                                          pj_ssize_t *length, 
    563                                           unsigned flags, 
     571                                          pj_uint32_t flags, 
    564572                                          pj_sockaddr_t *addr, 
    565573                                          int *addrlen); 
     
    588596 *                  variable on caller's stack and doesn't have to remain  
    589597 *                  valid until the operation has completed. 
    590  * @param flags     Send flags. 
     598 * @param flags     Send flags. If flags has PJ_IOQUEUE_ALWAYS_ASYNC then 
     599 *                  the function will never return PJ_SUCCESS. 
    591600 * 
    592601 * @return 
     
    602611                                      const void *data, 
    603612                                      pj_ssize_t *length, 
    604                                       unsigned flags ); 
     613                                      pj_uint32_t flags ); 
    605614 
    606615 
     
    628637 *                  variable on caller's stack and doesn't have to remain  
    629638 *                  valid until the operation has completed. 
    630  * @param flags     send flags. 
     639 * @param flags     send flags. If flags has PJ_IOQUEUE_ALWAYS_ASYNC then 
     640 *                  the function will never return PJ_SUCCESS. 
    631641 * @param addr      Optional remote address. 
    632642 * @param addrlen   Remote address length, \c addr is specified. 
     
    641651                                        const void *data, 
    642652                                        pj_ssize_t *length, 
    643                                         unsigned flags, 
     653                                        pj_uint32_t flags, 
    644654                                        const pj_sockaddr_t *addr, 
    645655                                        int addrlen); 
  • pjproject/trunk/pjlib/src/pj/ioqueue_common_abs.c

    r51 r55  
    492492                                      unsigned flags ) 
    493493{ 
    494     pj_status_t status; 
    495     pj_ssize_t size; 
    496494    struct read_operation *read_op; 
    497495 
     
    504502    /* Try to see if there's data immediately available.  
    505503     */ 
    506     size = *length; 
    507     status = pj_sock_recv(key->fd, buffer, &size, flags); 
    508     if (status == PJ_SUCCESS) { 
    509         /* Yes! Data is available! */ 
    510         *length = size; 
    511         return PJ_SUCCESS; 
    512     } else { 
    513         /* If error is not EWOULDBLOCK (or EAGAIN on Linux), report 
    514          * the error to caller. 
    515          */ 
    516         if (status != PJ_STATUS_FROM_OS(PJ_BLOCKING_ERROR_VAL)) 
    517             return status; 
    518     } 
     504    if ((flags & PJ_IOQUEUE_ALWAYS_ASYNC) == 0) { 
     505        pj_status_t status; 
     506        pj_ssize_t size; 
     507 
     508        size = *length; 
     509        status = pj_sock_recv(key->fd, buffer, &size, flags); 
     510        if (status == PJ_SUCCESS) { 
     511            /* Yes! Data is available! */ 
     512            *length = size; 
     513            return PJ_SUCCESS; 
     514        } else { 
     515            /* If error is not EWOULDBLOCK (or EAGAIN on Linux), report 
     516             * the error to caller. 
     517             */ 
     518            if (status != PJ_STATUS_FROM_OS(PJ_BLOCKING_ERROR_VAL)) 
     519                return status; 
     520        } 
     521    } 
     522 
     523    flags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); 
    519524 
    520525    /* 
     
    548553                                         int *addrlen) 
    549554{ 
    550     pj_status_t status; 
    551     pj_ssize_t size; 
    552555    struct read_operation *read_op; 
    553556 
     
    560563    /* Try to see if there's data immediately available.  
    561564     */ 
    562     size = *length; 
    563     status = pj_sock_recvfrom(key->fd, buffer, &size, flags, 
    564                               addr, addrlen); 
    565     if (status == PJ_SUCCESS) { 
    566         /* Yes! Data is available! */ 
    567         *length = size; 
    568         return PJ_SUCCESS; 
    569     } else { 
    570         /* If error is not EWOULDBLOCK (or EAGAIN on Linux), report 
    571          * the error to caller. 
    572          */ 
    573         if (status != PJ_STATUS_FROM_OS(PJ_BLOCKING_ERROR_VAL)) 
    574             return status; 
    575     } 
     565    if ((flags & PJ_IOQUEUE_ALWAYS_ASYNC) == 0) { 
     566        pj_status_t status; 
     567        pj_ssize_t size; 
     568 
     569        size = *length; 
     570        status = pj_sock_recvfrom(key->fd, buffer, &size, flags, 
     571                                  addr, addrlen); 
     572        if (status == PJ_SUCCESS) { 
     573            /* Yes! Data is available! */ 
     574            *length = size; 
     575            return PJ_SUCCESS; 
     576        } else { 
     577            /* If error is not EWOULDBLOCK (or EAGAIN on Linux), report 
     578             * the error to caller. 
     579             */ 
     580            if (status != PJ_STATUS_FROM_OS(PJ_BLOCKING_ERROR_VAL)) 
     581                return status; 
     582        } 
     583    } 
     584 
     585    flags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); 
    576586 
    577587    /* 
     
    614624    write_op = (struct write_operation*)op_key; 
    615625    write_op->op = 0; 
     626 
     627    /* We can not use PJ_IOQUEUE_ALWAYS_ASYNC for socket write. */ 
     628    flags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); 
    616629 
    617630    /* Fast track: 
     
    676689                                       const void *data, 
    677690                                       pj_ssize_t *length, 
    678                                        unsigned flags, 
     691                                       pj_uint32_t flags, 
    679692                                       const pj_sockaddr_t *addr, 
    680693                                       int addrlen) 
     
    689702    write_op = (struct write_operation*)op_key; 
    690703    write_op->op = 0; 
     704 
     705    /* We can not use PJ_IOQUEUE_ALWAYS_ASYNC for socket write */ 
     706    flags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); 
    691707 
    692708    /* Fast track: 
  • pjproject/trunk/pjlib/src/pj/ioqueue_winnt.c

    r51 r55  
    530530                                      void *buffer, 
    531531                                      pj_ssize_t *length, 
    532                                       unsigned flags ) 
     532                                      pj_uint32_t flags ) 
    533533{ 
    534534    /* 
     
    554554     * immediately available. 
    555555     */ 
    556     rc = WSARecv((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, 
    557                  &bytesRead, &dwFlags, NULL, NULL); 
    558     if (rc == 0) { 
    559         *length = bytesRead; 
    560         return PJ_SUCCESS; 
    561     } else { 
    562         DWORD dwError = WSAGetLastError(); 
    563         if (dwError != WSAEWOULDBLOCK) { 
    564             *length = -1; 
    565             return PJ_RETURN_OS_ERROR(dwError); 
    566         } 
    567     } 
     556    if ((flags & PJ_IOQUEUE_ALWAYS_ASYNC) == 0) { 
     557        rc = WSARecv((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, 
     558                     &bytesRead, &dwFlags, NULL, NULL); 
     559        if (rc == 0) { 
     560            *length = bytesRead; 
     561            return PJ_SUCCESS; 
     562        } else { 
     563            DWORD dwError = WSAGetLastError(); 
     564            if (dwError != WSAEWOULDBLOCK) { 
     565                *length = -1; 
     566                return PJ_RETURN_OS_ERROR(dwError); 
     567            } 
     568        } 
     569    } 
     570 
     571    dwFlags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); 
    568572 
    569573    /* 
     
    599603                                         void *buffer, 
    600604                                         pj_ssize_t *length, 
    601                                          unsigned flags, 
     605                                         pj_uint32_t flags, 
    602606                                         pj_sockaddr_t *addr, 
    603607                                         int *addrlen) 
     
    620624     * immediately available. 
    621625     */ 
    622     rc = WSARecvFrom((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, 
    623                      &bytesRead, &dwFlags, addr, addrlen, NULL, NULL); 
    624     if (rc == 0) { 
    625         *length = bytesRead; 
    626         return PJ_SUCCESS; 
    627     } else { 
    628         DWORD dwError = WSAGetLastError(); 
    629         if (dwError != WSAEWOULDBLOCK) { 
    630             *length = -1; 
    631             return PJ_RETURN_OS_ERROR(dwError); 
    632         } 
    633     } 
     626    if ((flags & PJ_IOQUEUE_ALWAYS_ASYNC) == 0) { 
     627        rc = WSARecvFrom((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, 
     628                         &bytesRead, &dwFlags, addr, addrlen, NULL, NULL); 
     629        if (rc == 0) { 
     630            *length = bytesRead; 
     631            return PJ_SUCCESS; 
     632        } else { 
     633            DWORD dwError = WSAGetLastError(); 
     634            if (dwError != WSAEWOULDBLOCK) { 
     635                *length = -1; 
     636                return PJ_RETURN_OS_ERROR(dwError); 
     637            } 
     638        } 
     639    } 
     640 
     641    dwFlags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); 
    634642 
    635643    /* 
     
    665673                                      const void *data, 
    666674                                      pj_ssize_t *length, 
    667                                       unsigned flags ) 
     675                                      pj_uint32_t flags ) 
    668676{ 
    669677    return pj_ioqueue_sendto(key, op_key, data, length, flags, NULL, 0); 
     
    680688                                       const void *data, 
    681689                                       pj_ssize_t *length, 
    682                                        unsigned flags, 
     690                                       pj_uint32_t flags, 
    683691                                       const pj_sockaddr_t *addr, 
    684692                                       int addrlen) 
     
    694702    op_key_rec = (union operation_key*)op_key->internal__; 
    695703 
    696     dwFlags = flags; 
    697  
    698704    /* 
    699705     * First try blocking write. 
     
    702708    op_key_rec->overlapped.wsabuf.len = *length; 
    703709 
    704     rc = WSASendTo((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, 
    705                    &bytesWritten, dwFlags, addr, addrlen, 
    706                    NULL, NULL); 
    707     if (rc == 0) { 
    708         *length = bytesWritten; 
    709         return PJ_SUCCESS; 
    710     } else { 
    711         DWORD dwStatus = WSAGetLastError(); 
    712         if (dwStatus != WSAEWOULDBLOCK) { 
    713             *length = -1; 
    714             return PJ_RETURN_OS_ERROR(dwStatus); 
    715         } 
    716     } 
     710    dwFlags = flags; 
     711 
     712    if ((flags & PJ_IOQUEUE_ALWAYS_ASYNC) == 0) { 
     713        rc = WSASendTo((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, 
     714                       &bytesWritten, dwFlags, addr, addrlen, 
     715                       NULL, NULL); 
     716        if (rc == 0) { 
     717            *length = bytesWritten; 
     718            return PJ_SUCCESS; 
     719        } else { 
     720            DWORD dwStatus = WSAGetLastError(); 
     721            if (dwStatus != WSAEWOULDBLOCK) { 
     722                *length = -1; 
     723                return PJ_RETURN_OS_ERROR(dwStatus); 
     724            } 
     725        } 
     726    } 
     727 
     728    dwFlags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); 
    717729 
    718730    /* 
Note: See TracChangeset for help on using the changeset viewer.