- Timestamp:
- Nov 19, 2005 1:19:28 PM (19 years ago)
- Location:
- pjproject/trunk/pjlib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/ioqueue.h
r51 r55 234 234 # define PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL (16) 235 235 #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) 236 242 237 243 /** … … 506 512 * caller's stack and doesn't have to remain valid for the 507 513 * 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. 509 516 * 510 517 * @return … … 519 526 void *buffer, 520 527 pj_ssize_t *length, 521 unsignedflags );528 pj_uint32_t flags ); 522 529 523 530 /** … … 543 550 * caller's stack and doesn't have to remain valid for the 544 551 * 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. 546 554 * @param addr Optional Pointer to buffer to receive the address. 547 555 * @param addrlen On input, specifies the length of the address buffer. … … 561 569 void *buffer, 562 570 pj_ssize_t *length, 563 unsignedflags,571 pj_uint32_t flags, 564 572 pj_sockaddr_t *addr, 565 573 int *addrlen); … … 588 596 * variable on caller's stack and doesn't have to remain 589 597 * 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. 591 600 * 592 601 * @return … … 602 611 const void *data, 603 612 pj_ssize_t *length, 604 unsignedflags );613 pj_uint32_t flags ); 605 614 606 615 … … 628 637 * variable on caller's stack and doesn't have to remain 629 638 * 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. 631 641 * @param addr Optional remote address. 632 642 * @param addrlen Remote address length, \c addr is specified. … … 641 651 const void *data, 642 652 pj_ssize_t *length, 643 unsignedflags,653 pj_uint32_t flags, 644 654 const pj_sockaddr_t *addr, 645 655 int addrlen); -
pjproject/trunk/pjlib/src/pj/ioqueue_common_abs.c
r51 r55 492 492 unsigned flags ) 493 493 { 494 pj_status_t status;495 pj_ssize_t size;496 494 struct read_operation *read_op; 497 495 … … 504 502 /* Try to see if there's data immediately available. 505 503 */ 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); 519 524 520 525 /* … … 548 553 int *addrlen) 549 554 { 550 pj_status_t status;551 pj_ssize_t size;552 555 struct read_operation *read_op; 553 556 … … 560 563 /* Try to see if there's data immediately available. 561 564 */ 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); 576 586 577 587 /* … … 614 624 write_op = (struct write_operation*)op_key; 615 625 write_op->op = 0; 626 627 /* We can not use PJ_IOQUEUE_ALWAYS_ASYNC for socket write. */ 628 flags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); 616 629 617 630 /* Fast track: … … 676 689 const void *data, 677 690 pj_ssize_t *length, 678 unsignedflags,691 pj_uint32_t flags, 679 692 const pj_sockaddr_t *addr, 680 693 int addrlen) … … 689 702 write_op = (struct write_operation*)op_key; 690 703 write_op->op = 0; 704 705 /* We can not use PJ_IOQUEUE_ALWAYS_ASYNC for socket write */ 706 flags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC); 691 707 692 708 /* Fast track: -
pjproject/trunk/pjlib/src/pj/ioqueue_winnt.c
r51 r55 530 530 void *buffer, 531 531 pj_ssize_t *length, 532 unsignedflags )532 pj_uint32_t flags ) 533 533 { 534 534 /* … … 554 554 * immediately available. 555 555 */ 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); 568 572 569 573 /* … … 599 603 void *buffer, 600 604 pj_ssize_t *length, 601 unsignedflags,605 pj_uint32_t flags, 602 606 pj_sockaddr_t *addr, 603 607 int *addrlen) … … 620 624 * immediately available. 621 625 */ 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); 634 642 635 643 /* … … 665 673 const void *data, 666 674 pj_ssize_t *length, 667 unsignedflags )675 pj_uint32_t flags ) 668 676 { 669 677 return pj_ioqueue_sendto(key, op_key, data, length, flags, NULL, 0); … … 680 688 const void *data, 681 689 pj_ssize_t *length, 682 unsignedflags,690 pj_uint32_t flags, 683 691 const pj_sockaddr_t *addr, 684 692 int addrlen) … … 694 702 op_key_rec = (union operation_key*)op_key->internal__; 695 703 696 dwFlags = flags;697 698 704 /* 699 705 * First try blocking write. … … 702 708 op_key_rec->overlapped.wsabuf.len = *length; 703 709 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); 717 729 718 730 /*
Note: See TracChangeset
for help on using the changeset viewer.