Minor cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19174 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
88008dd688
commit
774e1e2116
@ -210,6 +210,7 @@ TCPConnection::Free()
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Creates and sends a SYN packet to /a address
|
||||
*/
|
||||
@ -356,6 +357,7 @@ TCPConnection::Listen(int count)
|
||||
BenaphoreLocker lock(&fLock);
|
||||
if (fState != CLOSED)
|
||||
return B_ERROR;
|
||||
|
||||
fState = LISTEN;
|
||||
return B_OK;
|
||||
}
|
||||
@ -376,19 +378,17 @@ status_t
|
||||
TCPConnection::SendData(net_buffer *buffer)
|
||||
{
|
||||
TRACE(("TCP:%p.SendData()\n", this));
|
||||
size_t bufSize = buffer->size;
|
||||
size_t bufferSize = buffer->size;
|
||||
BenaphoreLocker lock(&fLock);
|
||||
if (fSendBuffer == NULL) {
|
||||
fSendBuffer = buffer;
|
||||
fNextByteToWrite += bufSize;
|
||||
return SendQueuedData(TCP_FLG_ACK, false);
|
||||
} else {
|
||||
if (fSendBuffer != NULL) {
|
||||
status_t status = sBufferModule->merge(fSendBuffer, buffer, true);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
fNextByteToWrite += bufSize;
|
||||
} else
|
||||
fSendBuffer = buffer;
|
||||
|
||||
fNextByteToWrite += bufferSize;
|
||||
return SendQueuedData(TCP_FLG_ACK, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -411,13 +411,13 @@ TCPConnection::SendAvailable()
|
||||
BenaphoreLocker lock(&fLock);
|
||||
if (fSendBuffer != NULL)
|
||||
return TCP_MAX_SEND_BUF - fSendBuffer->size;
|
||||
else
|
||||
|
||||
return TCP_MAX_SEND_BUF;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TCPConnection::ReadData(size_t numBytes, uint32 flags, net_buffer **buffer)
|
||||
TCPConnection::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
|
||||
{
|
||||
TRACE(("TCP:%p.ReadData()\n", this));
|
||||
|
||||
@ -426,19 +426,22 @@ TCPConnection::ReadData(size_t numBytes, uint32 flags, net_buffer **buffer)
|
||||
// must be in a synchronous state
|
||||
if (fState != ESTABLISHED || fState != FIN_WAIT1 || fState != FIN_WAIT2) {
|
||||
// is this correct semantics?
|
||||
dprintf(" TCP state = %d\n", fState);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
dprintf(" TCP error = %ld\n", fError);
|
||||
if (fError != B_OK)
|
||||
return fError;
|
||||
|
||||
if (fReceiveBuffer->size < numBytes)
|
||||
numBytes = fReceiveBuffer->size;
|
||||
*buffer = sBufferModule->split(fReceiveBuffer, numBytes);
|
||||
if (*buffer != NULL)
|
||||
|
||||
*_buffer = sBufferModule->split(fReceiveBuffer, numBytes);
|
||||
if (*_buffer == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
return B_OK;
|
||||
else
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@ -449,7 +452,7 @@ TCPConnection::ReadAvailable()
|
||||
BenaphoreLocker lock(&fLock);
|
||||
if (fReceiveBuffer != NULL)
|
||||
return fReceiveBuffer->size;
|
||||
else
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -457,7 +460,7 @@ TCPConnection::ReadAvailable()
|
||||
status_t
|
||||
TCPConnection::EnqueueReceivedData(net_buffer *buffer, uint32 sequenceNumber)
|
||||
{
|
||||
TRACE(("TCP:%p.EnqueueReceivedData(%p, %u)\n", this, buffer, sequenceNumber));
|
||||
TRACE(("TCP:%p.EnqueueReceivedData(%p, %lu)\n", this, buffer, sequenceNumber));
|
||||
status_t status;
|
||||
|
||||
if (sequenceNumber == fNextByteExpected) {
|
||||
@ -550,9 +553,9 @@ TCPConnection::ReceiveData(net_buffer *buffer)
|
||||
sBufferModule->free(buffer);
|
||||
if (header.flags & TCP_FLG_ACK)
|
||||
return Reset(byteAckd, 0);
|
||||
else
|
||||
|
||||
return Reset(0, byteRcvd + payloadLength);
|
||||
break;
|
||||
|
||||
case LISTEN:
|
||||
// if packet is SYN, spawn new TCPConnection in SYN_RCVD state
|
||||
// and add it to the Connection Queue. The new TCPConnection
|
||||
@ -562,19 +565,22 @@ TCPConnection::ReceiveData(net_buffer *buffer)
|
||||
// Otherwise, RST+ACK is sent.
|
||||
// The current TCPConnection always remains in LISTEN state.
|
||||
return B_ERROR;
|
||||
break;
|
||||
|
||||
case SYN_SENT:
|
||||
if (header.flags & TCP_FLG_RST) {
|
||||
fError = ECONNREFUSED;
|
||||
fState = CLOSED;
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
if (header.flags & TCP_FLG_ACK && !TCP_IS_GOOD_ACK(byteAckd))
|
||||
return Reset(byteAckd, 0);
|
||||
|
||||
if (header.flags & TCP_FLG_SYN) {
|
||||
fNextByteToRead = fNextByteExpected = ntohl(header.sequence_num) + 1;
|
||||
flags |= TCP_FLG_ACK;
|
||||
fLastByteAckd = byteAckd;
|
||||
|
||||
// cancel resend of this segment
|
||||
if (header.flags & TCP_FLG_ACK)
|
||||
nextState = ESTABLISHED;
|
||||
@ -584,12 +590,14 @@ TCPConnection::ReceiveData(net_buffer *buffer)
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SYN_RCVD:
|
||||
if (header.flags & TCP_FLG_ACK && TCP_IS_GOOD_ACK(byteAckd))
|
||||
fState = ESTABLISHED;
|
||||
else
|
||||
Reset(byteAckd, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
// In a synchronized state.
|
||||
// first check that the received sequence number is good
|
||||
@ -600,6 +608,7 @@ TCPConnection::ReceiveData(net_buffer *buffer)
|
||||
fState = CLOSED;
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
if (header.flags & TCP_FLG_ACK && TCP_IS_GOOD_ACK(byteAckd) ) {
|
||||
fLastByteAckd = byteAckd;
|
||||
if (fLastByteAckd == fNextByteToWrite) {
|
||||
@ -675,7 +684,6 @@ TCPConnection::ReceiveData(net_buffer *buffer)
|
||||
}
|
||||
|
||||
fState = nextState;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -788,10 +796,10 @@ TCPConnection::Compare(void *_connection, const void *_key)
|
||||
const tcp_connection_key *key = (tcp_connection_key *)_key;
|
||||
TCPConnection *connection= ((TCPConnection *)_connection);
|
||||
|
||||
if (sAddressModule->equal_addresses_and_ports(
|
||||
key->local, (sockaddr *)&connection->socket->address)
|
||||
&& sAddressModule->equal_addresses_and_ports(
|
||||
key->peer, (sockaddr *)&connection->socket->peer))
|
||||
if (sAddressModule->equal_addresses_and_ports(key->local,
|
||||
(sockaddr *)&connection->socket->address)
|
||||
&& sAddressModule->equal_addresses_and_ports(key->peer,
|
||||
(sockaddr *)&connection->socket->peer))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user