tcp.cpp revision f53590da7cec1b284ea1ccba4f77bc2d96718e30
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * InnoTek Portable Runtime - TCP/IP.
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * Copyright (C) 2006 InnoTek Systemberatung GmbH
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * available from http://www.virtualbox.org. This file is free software;
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * General Public License as published by the Free Software Foundation,
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * If you received this file as part of a commercial VirtualBox
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * distribution, then only the terms of your commercial VirtualBox
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync * license agreement apply instead of the previous paragraph.
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync/*******************************************************************************
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync* Header Files *
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync*******************************************************************************/
a33af978add1a03aab11b2895f441af5cb2a11a6vboxsync#else /* !__WIN__ */
#include <netdb.h>
#include <unistd.h>
#ifndef MSG_NOSIGNAL
# define MSG_NOSIGNAL 0
#ifndef SHUT_RDWR
# ifdef SD_BOTH
# define socklen_t int
typedef enum RTTCPSERVERSTATE
typedef struct RTTCPSERVER
void *pvUser;
} RTTCPSERVER;
inline int rtTcpError(void)
#ifdef __WIN__
switch (sizeof(RTSOCKET))
return NIL_RTSOCKET;
inline bool rtTcpServerSetState(PRTTCPSERVER pServer, RTTCPSERVERSTATE enmStateNew, RTTCPSERVERSTATE enmStateOld)
bool fRc;
return fRc;
RTR3DECL(int) RTTcpServerCreate(const char *pszAddress, unsigned uPort, RTTHREADTYPE enmType, const char *pszThrdName,
return VERR_INVALID_PARAMETER;
rc = RTThreadCreate(&pServer->Thread, rtTcpServerThread, pServer, 0, enmType, /*RTTHREADFLAGS_WAITABLE*/0, pszThrdName);
if (ppServer)
return rc;
return rc;
return VINF_SUCCESS;
int rc;
return VERR_INVALID_PARAMETER;
#ifdef __WIN__
return VERR_NOT_SUPPORTED;
if (!pHostEnt)
if (!pHostEnt)
return rc;
if (!pHostEnt)
if (pServer)
return VINF_SUCCESS;
return rc;
return VERR_INVALID_PARAMETER;
return VERR_INVALID_PARAMETER;
#ifndef __WIN__
return rc;
return rc;
switch (enmState)
if (!RTThreadYield())
AssertMsgFailed(("Timed out when trying to clean up after listener. pServer=%p enmState=%d\n", pServer, pServer->enmState));
if ( !pServer
return VERR_INVALID_PARAMETER;
if ( !pServer
return VERR_INVALID_PARAMETER;
/** @todo r=bird: Some of this horrible code can probably be exchanged with a RTThreadWait(). (It didn't exist when this code was written.) */
switch (enmState)
case RTTCPSERVERSTATE_SERVING:
return VINF_SUCCESS;
if (!RTThreadYield())
case RTTCPSERVERSTATE_CREATED:
case RTTCPSERVERSTATE_STOPPED:
return VINF_TCP_SERVER_STOP;
return VERR_INTERNAL_ERROR;
return VERR_INTERNAL_ERROR;
return VERR_INVALID_PARAMETER;
if (cbBytesRead < 0)
return rtTcpError();
return rtTcpError();
if (pcbRead)
return VINF_SUCCESS;
if (cbWritten < 0)
return rtTcpError();
AssertMsg(cbBuffer >= (size_t)cbWritten, ("Wrote more than we requested!!! cbWritten=%d cbBuffer=%d rtTcpError()=%d\n",
} while (cbBuffer);
return VINF_SUCCESS;
fFlag = 0;
return VINF_SUCCESS;
int rc;
if (rc > 0)
return VINF_SUCCESS;
if (rc == 0)
return VERR_TIMEOUT;
return rtTcpError();
int rc;
#ifdef __WIN__
return VERR_NOT_SUPPORTED;
if (!pHostEnt)
if (!pHostEnt)
return rc;
return VINF_SUCCESS;
return rc;
return VINF_SUCCESS;
#ifdef __WIN__
if (!rc)
return VINF_SUCCESS;
return rc;