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