Changeset 26683 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Feb 22, 2010 4:43:37 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/message.cpp
r26674 r26683 99 99 100 100 101 RTDECL(int) RTMsgInitFailure(int rcRTR3Init) 101 RTDECL(RTEXITCODE) RTMsgErrorExit(RTEXITCODE enmExitCode, const char *pszFormat, ...) 102 { 103 va_list va; 104 va_start(va, pszFormat); 105 RTMsgErrorV(pszFormat, va); 106 va_end(va); 107 return enmExitCode; 108 } 109 RT_EXPORT_SYMBOL(RTMsgErrorExitV); 110 111 112 RTDECL(RTEXITCODE) RTMsgErrorExitV(RTEXITCODE enmExitCode, const char *pszFormat, va_list va) 113 { 114 RTMsgErrorV(pszFormat, va); 115 return enmExitCode; 116 } 117 RT_EXPORT_SYMBOL(RTMsgErrorExitV); 118 119 120 RTDECL(RTEXITCODE) RTMsgInitFailure(int rcRTR3Init) 102 121 { 103 122 if ( g_offrtProcName … … 108 127 else 109 128 RTStrmPrintf(g_pStdErr, "fatal error: RTR3Init: %Rrc\n", rcRTR3Init); 110 return 12;129 return RTEXITCODE_INIT; 111 130 } 112 131 RT_EXPORT_SYMBOL(RTMsgInitFailure); -
trunk/src/VBox/Runtime/r3/tcp.cpp
r26612 r26683 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Sun Microsystems, Inc.7 * Copyright (C) 2006-2010 Sun Microsystems, Inc. 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 35 35 #ifdef RT_OS_WINDOWS 36 36 # include <winsock.h> 37 # include <limits.h>38 37 #else /* !RT_OS_WINDOWS */ 39 38 # include <errno.h> … … 50 49 # include <unistd.h> 51 50 #endif /* !RT_OS_WINDOWS */ 51 #include <limits.h> 52 52 53 53 #include "internal/iprt.h" … … 657 657 658 658 /** 659 * Listen and accept one incomming connection. 660 * 661 * This is an alternative to RTTcpServerListen for the use the callbacks are not 662 * possible. 663 * 664 * @returns IPRT status code. 665 * @retval VERR_TCP_SERVER_SHUTDOWN if shut down by RTTcpServerShutdown. 666 * @retval VERR_INTERRUPTED if the listening was interrupted. 667 * 668 * @param pServer The server handle as returned from RTTcpServerCreateEx(). 669 * @param pSockClient Where to return the socket handle to the client 670 * connection (on success only). Use 671 * RTTcpServerDisconnectClient() to clean it, this must 672 * be done before the next call to RTTcpServerListen2. 673 * 674 * @todo This can easily be extended to support multiple connections by 675 * adding a new state and a RTTcpServerDisconnectClient variant for 676 * closing client sockets. 677 */ 678 RTR3DECL(int) RTTcpServerListen2(PRTTCPSERVER pServer, PRTSOCKET pSockClient) 679 { 680 /* 681 * Validate input and retain the instance. 682 */ 683 AssertPtrReturn(pSockClient, VERR_INVALID_HANDLE); 684 *pSockClient = NIL_RTSOCKET; 685 AssertReturn(pServer->u32Magic == RTTCPSERVER_MAGIC, VERR_INVALID_HANDLE); 686 AssertReturn(RTMemPoolRetain(pServer) != UINT32_MAX, VERR_INVALID_HANDLE); 687 688 int rc = VERR_INVALID_STATE; 689 for (;;) 690 { 691 /* 692 * Change state to accepting. 693 */ 694 RTTCPSERVERSTATE enmState = pServer->enmState; 695 RTSOCKET SockServer = pServer->SockServer; 696 if ( enmState != RTTCPSERVERSTATE_SERVING 697 && enmState != RTTCPSERVERSTATE_CREATED) 698 { 699 rc = rcTcpServerListenCleanup(pServer); 700 break; 701 } 702 if (!rtTcpServerTrySetState(pServer, RTTCPSERVERSTATE_ACCEPTING, enmState)) 703 continue; 704 Assert(!pServer->pfnServe); 705 Assert(!pServer->pvUser); 706 Assert(pServer->Thread == NIL_RTTHREAD); 707 Assert(pServer->SockClient == NIL_RTSOCKET); 708 709 /* 710 * Accept connection. 711 */ 712 struct sockaddr_in RemoteAddr; 713 socklen_t cbRemoteAddr = sizeof(RemoteAddr); 714 RTSOCKET Socket; 715 RT_ZERO(RemoteAddr); 716 rtTcpErrorReset(); 717 Socket = accept(SockServer, (struct sockaddr *)&RemoteAddr, &cbRemoteAddr); 718 if (Socket == -1) 719 { 720 rc = rtTcpError(); 721 if (!rtTcpServerTrySetState(pServer, RTTCPSERVERSTATE_CREATED, RTTCPSERVERSTATE_ACCEPTING)) 722 rc = rcTcpServerListenCleanup(pServer); 723 if (RT_FAILURE(rc)) 724 break; 725 continue; 726 } 727 728 /* 729 * Chance to the 'serving' state and return the socket. 730 */ 731 if (rtTcpServerTrySetState(pServer, RTTCPSERVERSTATE_SERVING, RTTCPSERVERSTATE_ACCEPTING)) 732 { 733 *pSockClient = Socket; 734 rc = VINF_SUCCESS; 735 } 736 else 737 { 738 rtTcpClose(Socket, "RTTcpServerListen2", true /*fTryGracefulShutdown*/); 739 rc = rcTcpServerListenCleanup(pServer); 740 } 741 break; 742 } 743 744 RTMemPoolRelease(RTMEMPOOL_DEFAULT, pServer); 745 return rc; 746 } 747 748 749 /** 659 750 * Terminate the open connection to the server. 660 751 * … … 855 946 RTR3DECL(int) RTTcpWrite(RTSOCKET Sock, const void *pvBuffer, size_t cbBuffer) 856 947 { 857 858 do859 {948 /* 949 * Try write all at once. 950 */ 860 951 #ifdef RT_OS_WINDOWS 861 int cbNow = cbBuffer >= INT_MAX/2 ? INT_MAX/2 : (int)cbBuffer;952 int cbNow = cbBuffer >= INT_MAX / 2 ? INT_MAX / 2 : (int)cbBuffer; 862 953 #else 863 size_t cbNow = cbBuffer; 864 #endif 865 ssize_t cbWritten = send(Sock, (const char *)pvBuffer, cbNow, MSG_NOSIGNAL); 866 if (cbWritten < 0) 867 return rtTcpError(); 868 AssertMsg(cbBuffer >= (size_t)cbWritten, ("Wrote more than we requested!!! cbWritten=%d cbBuffer=%d rtTcpError()=%d\n", 869 cbWritten, cbBuffer, rtTcpError())); 870 cbBuffer -= cbWritten; 871 pvBuffer = (char *)pvBuffer + cbWritten; 872 } while (cbBuffer); 873 874 return VINF_SUCCESS; 954 size_t cbNow = cbBuffer >= SSIZE_MAX ? SSIZE_MAX : cbBuffer; 955 #endif 956 ssize_t cbWritten = send(Sock, (const char *)pvBuffer, cbNow, MSG_NOSIGNAL); 957 if (RT_LIKELY((size_t)cbWritten == cbBuffer && cbWritten >= 0)) 958 return VINF_SUCCESS; 959 if (cbWritten < 0) 960 return rtTcpError(); 961 962 /* 963 * Unfinished business, write the remainder of the request. Must ignore 964 * VERR_INTERRUPTED here if we've managed to send something. 965 */ 966 size_t cbSentSoFar = 0; 967 for (;;) 968 { 969 /* advance */ 970 cbBuffer -= (size_t)cbWritten; 971 if (!cbBuffer) 972 return VINF_SUCCESS; 973 cbSentSoFar += (size_t)cbWritten; 974 pvBuffer = (char const *)pvBuffer + cbWritten; 975 976 /* send */ 977 #ifdef RT_OS_WINDOWS 978 cbNow = cbBuffer >= INT_MAX / 2 ? INT_MAX / 2 : (int)cbBuffer; 979 #else 980 cbNow = cbBuffer >= SSIZE_MAX ? SSIZE_MAX : cbBuffer; 981 #endif 982 cbWritten = send(Sock, (const char *)pvBuffer, cbNow, MSG_NOSIGNAL); 983 if (cbWritten >= 0) 984 AssertMsg(cbBuffer >= (size_t)cbWritten, ("Wrote more than we requested!!! cbWritten=%zu cbBuffer=%zu rtTcpError()=%d\n", 985 cbWritten, cbBuffer, rtTcpError())); 986 else 987 { 988 int rc = rtTcpError(); 989 if (rc != VERR_INTERNAL_ERROR || cbSentSoFar == 0) 990 return rc; 991 cbWritten = 0; 992 } 993 } 875 994 } 876 995 -
trunk/src/VBox/Runtime/r3/test.cpp
r25645 r26683 289 289 290 290 291 RTR3DECL( int) RTTestInitAndCreate(const char *pszTest, PRTTEST phTest)291 RTR3DECL(RTEXITCODE) RTTestInitAndCreate(const char *pszTest, PRTTEST phTest) 292 292 { 293 293 int rc = RTR3Init(); … … 295 295 { 296 296 RTStrmPrintf(g_pStdErr, "%s: fatal error: RTR3Init failed with rc=%Rrc\n", pszTest, rc); 297 return 16;297 return RTEXITCODE_INIT; 298 298 } 299 299 rc = RTTestCreate(pszTest, phTest); … … 301 301 { 302 302 RTStrmPrintf(g_pStdErr, "%s: fatal error: RTTestCreate failed with rc=%Rrc\n", pszTest, rc); 303 return 17;304 } 305 return 0;303 return RTEXITCODE_INIT; 304 } 305 return RTEXITCODE_SUCCESS; 306 306 } 307 307 … … 806 806 * associated with the calling thread. 807 807 */ 808 RTR3DECL( int) RTTestSummaryAndDestroy(RTTEST hTest)808 RTR3DECL(RTEXITCODE) RTTestSummaryAndDestroy(RTTEST hTest) 809 809 { 810 810 PRTTESTINT pTest = hTest; 811 RTTEST_GET_VALID_RETURN_RC(pTest, 2);811 RTTEST_GET_VALID_RETURN_RC(pTest, RTEXITCODE_FAILURE); 812 812 813 813 RTCritSectEnter(&pTest->Lock); … … 815 815 RTCritSectLeave(&pTest->Lock); 816 816 817 int rc;817 RTEXITCODE enmExitCode; 818 818 if (!pTest->cErrors) 819 819 { 820 820 RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "SUCCESS\n", pTest->cErrors); 821 rc = 0;821 enmExitCode = RTEXITCODE_SUCCESS; 822 822 } 823 823 else 824 824 { 825 825 RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "FAILURE - %u errors\n", pTest->cErrors); 826 rc = 1;826 enmExitCode = RTEXITCODE_FAILURE; 827 827 } 828 828 829 829 RTTestDestroy(pTest); 830 return rc;831 } 832 833 834 RTR3DECL( int) RTTestSkipAndDestroyV(RTTEST hTest, const char *pszReasonFmt, va_list va)830 return enmExitCode; 831 } 832 833 834 RTR3DECL(RTEXITCODE) RTTestSkipAndDestroyV(RTTEST hTest, const char *pszReasonFmt, va_list va) 835 835 { 836 836 PRTTESTINT pTest = hTest; 837 RTTEST_GET_VALID_RETURN_RC(pTest, 2);837 RTTEST_GET_VALID_RETURN_RC(pTest, RTEXITCODE_SKIPPED); 838 838 839 839 RTCritSectEnter(&pTest->Lock); … … 841 841 RTCritSectLeave(&pTest->Lock); 842 842 843 int rc;843 RTEXITCODE enmExitCode; 844 844 if (!pTest->cErrors) 845 845 { … … 847 847 RTTestPrintfNlV(hTest, RTTESTLVL_FAILURE, pszReasonFmt, va); 848 848 RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "SKIPPED\n", pTest->cErrors); 849 rc = 2;849 enmExitCode = RTEXITCODE_SKIPPED; 850 850 } 851 851 else 852 852 { 853 853 RTTestPrintfNl(hTest, RTTESTLVL_ALWAYS, "FAILURE - %u errors\n", pTest->cErrors); 854 rc = 1;854 enmExitCode = RTEXITCODE_FAILURE; 855 855 } 856 856 857 857 RTTestDestroy(pTest); 858 return rc;859 } 860 861 862 RTR3DECL( int) RTTestSkipAndDestroy(RTTEST hTest, const char *pszReasonFmt, ...)858 return enmExitCode; 859 } 860 861 862 RTR3DECL(RTEXITCODE) RTTestSkipAndDestroy(RTTEST hTest, const char *pszReasonFmt, ...) 863 863 { 864 864 va_list va; 865 865 va_start(va, pszReasonFmt); 866 int rc= RTTestSkipAndDestroyV(hTest, pszReasonFmt, va);866 RTEXITCODE enmExitCode = RTTestSkipAndDestroyV(hTest, pszReasonFmt, va); 867 867 va_end(va); 868 return rc;868 return enmExitCode; 869 869 } 870 870
Note:
See TracChangeset
for help on using the changeset viewer.