DBGCTcp.cpp revision 98427c0ab08697e468c26dc33ee9571308577867
/* $Id$ */
/** @file
* DBGC - Debugger Console, TCP backend.
*/
/*
* Copyright (C) 2006-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Debug console TCP backend instance data.
*/
typedef struct DBGCTCP
{
/** The I/O backend for the console. */
/** The socket of the connection. */
/** Connection status. */
bool fAlive;
} DBGCTCP;
/** Pointer to the instance data of the console TCP backend. */
/** Converts a pointer to DBGCTCP::Back to a pointer to DBGCTCP. */
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
/**
* Checks if there is input.
*
* @returns true if there is input ready.
* @returns false if there not input ready.
* @param pBack Pointer to the backend structure supplied by
* the backend. The backend can use this to find
* it's instance data.
* @param cMillies Number of milliseconds to wait on input data.
*/
{
return false;
return rc != VERR_TIMEOUT;
}
/**
* Read input.
*
* @returns VBox status code.
* @param pBack Pointer to the backend structure supplied by
* the backend. The backend can use this to find
* it's instance data.
* @param pvBuf Where to put the bytes we read.
* @param cbBuf Maximum nymber of bytes to read.
* @param pcbRead Where to store the number of bytes actually read.
* If NULL the entire buffer must be filled for a
* successful return.
*/
static DECLCALLBACK(int) dbgcTcpBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead)
{
return VERR_INVALID_HANDLE;
if (RT_FAILURE(rc))
return rc;
}
/**
* Write (output).
*
* @returns VBox status code.
* @param pBack Pointer to the backend structure supplied by
* the backend. The backend can use this to find
* it's instance data.
* @param pvBuf What to write.
* @param cbBuf Number of bytes to write.
* @param pcbWritten Where to store the number of bytes actually written.
* If NULL the entire buffer must be successfully written.
*/
static DECLCALLBACK(int) dbgcTcpBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten)
{
return VERR_INVALID_HANDLE;
/*
* convert '\n' to '\r\n' while writing.
*/
int rc = 0;
while (cbLeft)
{
/* write newlines */
if (*(const char *)pvBuf == '\n')
{
cb = 1;
}
/* write till next newline */
else
{
if (pszNL)
}
if (RT_FAILURE(rc))
{
break;
}
/* advance */
}
/*
* Set returned value and return.
*/
if (pcbWritten)
return rc;
}
/** @copydoc FNDBGCBACKSETREADY */
{
/* stub */
}
/**
* Serve a TCP Server connection.
*
* @returns VBox status.
* @returns VERR_TCP_SERVER_STOP to terminate the server loop forcing
* the RTTcpCreateServer() call to return.
* @param Sock The socket which the client is connected to.
* The call will close this socket.
* @param pvUser The VM handle.
*/
{
/*
* Start the console.
*/
return rc;
}
/**
* Spawns a new thread with a TCP based debugging console service.
*
* @returns VBox status.
* @param pUVM The user mode VM handle.
* @param ppvData Where to store a pointer to the instance data.
*/
{
/*
* Check what the configuration says.
*/
bool fEnabled;
#if defined(VBOX_WITH_DEBUGGER) && defined(VBOX_WITH_DEBUGGER_TCP_BY_DEFAULT) && !defined(__L4ENV__) && !defined(DEBUG_dmik)
true
#else
false
#endif
);
if (RT_FAILURE(rc))
if (!fEnabled)
{
LogFlow(("DBGCTcpCreate: returns VINF_SUCCESS (Disabled)\n"));
return VINF_SUCCESS;
}
/*
* Get the port configuration.
*/
if (RT_FAILURE(rc))
/*
* Get the address configuration.
*/
char szAddress[512];
if (RT_FAILURE(rc))
/*
* Create the server (separate thread).
*/
rc = RTTcpServerCreate(szAddress, u32Port, RTTHREADTYPE_DEBUGGER, "DBGC", dbgcTcpConnection, pUVM, &pServer);
if (RT_SUCCESS(rc))
{
return rc;
}
}
/**
* Terminates any running TCP base debugger console service.
*
* @returns VBox status.
* @param pUVM The user mode VM handle.
* @param pvData The data returned by DBGCTcpCreate.
*/
{
/*
* Destroy the server instance if any.
*/
if (pvData)
{
}
return VINF_SUCCESS;
}