1
0
forked from 0ad/0ad

- Naming Convention\n- Documentation\n- Cleanup

This was SVN commit r187.
This commit is contained in:
Simon Brenner 2004-03-08 02:11:41 +00:00
parent f2de345f5e
commit 23e35513d3
2 changed files with 25 additions and 59 deletions

View File

@ -16,9 +16,9 @@ void *CStreamSocket_ConnectThread(void *data)
{
CStreamSocket *pSock=(CStreamSocket *)data;
PS_RESULT res=PS_OK;
SocketAddress addr;
CSocketAddress addr;
res=SocketAddress::Resolve(pSock->m_pConnectHost, pSock->m_ConnectPort, addr);
res=CSocketAddress::Resolve(pSock->m_pConnectHost, pSock->m_ConnectPort, addr);
if (res == PS_OK)
{
pSock->Initialize();
@ -26,11 +26,14 @@ void *CStreamSocket_ConnectThread(void *data)
res=pSock->Connect(addr);
}
pSock->SetNonBlocking(true);
if (res == PS_OK)
{
pSock->SetNonBlocking(true);
// This should call the right callbacks, so that you get the expected
// results if you call Read or Write before the connect actually is complete
pSock->SetOpMask((pSock->m_WriteContext.m_Valid?CSocketBase::WRITE:0)|CSocketBase::READ);
// This should call the right callbacks, so that you get the expected
// results if you call Read or Write before the connect actually is complete
pSock->SetOpMask((pSock->m_WriteContext.m_Valid?CSocketBase::WRITE:0)|CSocketBase::READ);
}
pSock->ConnectComplete(res);
@ -93,29 +96,10 @@ PS_RESULT CStreamSocket::Write(void *buf, uint len)
return PS_OK;
}
void CStreamSocket::Close()
{
//TODO Define
}
/*PS_RESULT CStreamSocket::GetRemoteAddress(u8 (&address)[4], int &port)
{
PS_RESULT res=GetStatus();
if (res == PS_OK)
CServerSocket::GetRemoteAddress(m_pInternal, address, port);
return res;
}*/
#define MakeDefaultCallback(_nm) void CStreamSocket::_nm(PS_RESULT error) \
{ printf("CStreamSocket::"#_nm"(): %s\n", error); }
void CStreamSocket::OnClose(PS_RESULT error)
{
printf("CStreamSocket::OnClose(): %s\n", error);
}
MakeDefaultCallback(OnClose)
MakeDefaultCallback(ConnectComplete)
MakeDefaultCallback(ReadComplete)
MakeDefaultCallback(WriteComplete)
@ -128,7 +112,10 @@ void CStreamSocket::OnWrite()
return;
}
uint bytes=0;
PS_RESULT res=CSocketBase::Write(((char *)m_WriteContext.m_pBuffer)+m_WriteContext.m_Completed, m_WriteContext.m_Length-m_WriteContext.m_Completed, &bytes);
PS_RESULT res=CSocketBase::Write(
((char *)m_WriteContext.m_pBuffer)+m_WriteContext.m_Completed,
m_WriteContext.m_Length-m_WriteContext.m_Completed,
&bytes);
if (res != PS_OK)
{
WriteComplete(res);
@ -156,7 +143,8 @@ void CStreamSocket::OnRead()
((char *)m_ReadContext.m_pBuffer)+m_ReadContext.m_Completed,
m_ReadContext.m_Length-m_ReadContext.m_Completed,
&bytes);
printf("CStreamSocket::OnRead(): %s, %u bytes read of %u\n", res, bytes, m_ReadContext.m_Length-m_ReadContext.m_Completed);
printf("CStreamSocket::OnRead(): %s, %u bytes read of %u\n", res, bytes,
m_ReadContext.m_Length-m_ReadContext.m_Completed);
if (res != PS_OK)
{
ReadComplete(res);

View File

@ -12,7 +12,7 @@
*/
class CStreamSocket: public CSocketBase
{
pthread_mutex_t m_Mutex;
CMutex m_Mutex;
char *m_pConnectHost;
int m_ConnectPort;
@ -52,22 +52,22 @@ public:
CStreamSocket();
/**
* The Lock function locks a mutex stored in the CSocket object. None of
* the CSocket methods actually use the mutex, it is just there as a
* convenience for the user.
* The Lock function locks a mutex stored in the CStreamSocket object. None
* of the CStreamSocket methods actually use the mutex, it is just there as
* a convenience for the user.
*/
void Lock();
/**
* The Unlock function unlocks a mutex stored in the CSocket object. None
* of the CSocket methods actually use the mutex, it is just there as a
* The Unlock function unlocks a mutex stored in the CStreamSocket object.
* None of the CSocket methods actually use the mutex, it is just there as a
* convenience for the user.
*/
void Unlock();
/**
* Begin a connect operation to the specified host and port. The connect
* attempt and name resolution is done in the background and the OnConnect
* callback is called when the connect is complete (or failed)
* operation and name resolution is performed in the background and the
* ConnectComplete callback is called when the connect is complete/failed
*
* Note that a PS_OK return only means that the connect operation has been
* initiated, not that it is successful.
@ -79,16 +79,6 @@ public:
*/
PS_RESULT BeginConnect(const char *hostname, int port);
/**
* Close the socket. No more data can be sent over the socket, but any data
* pending from the remote host will still be received, and the OnRead
* callback called (if the socket's op mask has the READ bit set). Note
* that the socket isn't actually closed until the remote end calls
* Close on the corresponding remote socket, upon which the OnClose
* callback is called.
*/
void Close();
/**
* Start a read operation. The function call will return immediately and
* complete the I/O in the background. OnRead() will be called when it is
@ -123,19 +113,7 @@ public:
*/
PS_RESULT Write(void *buf, uint len);
/**
* Get the address of the remote host connected to this socket.
*
* Inputs
* address The IP address of the remote host, in written order
* port The remote port number, in local byte order
*
* Returns
* PS_OK The remote address was successfully retrieved
* CONNECTION_BROKEN The socket is not connected
*/
//PS_RESULT GetRemoteAddress(u8 (&address)[4], int &port);
// The default implementation of these methods are no-ops
virtual void ConnectComplete(PS_RESULT errorCode);
virtual void ReadComplete(PS_RESULT errorCode);
virtual void WriteComplete(PS_RESULT errorCode);