diff --git a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp index 04d783b48c..4f27ef38df 100644 --- a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp @@ -8,7 +8,7 @@ #include "EndpointManager.h" -#include "TCPConnection.h" +#include "TCPEndpoint.h" #include @@ -45,10 +45,10 @@ static const uint16 kFirstEphemeralPort = 40000; EndpointManager::EndpointManager() { fConnectionHash = hash_init(kConnectionHashBuckets, - offsetof(TCPConnection, fConnectionHashNext), + offsetof(TCPEndpoint, fConnectionHashNext), &_ConnectionCompare, &_ConnectionHash); fEndpointHash = hash_init(kEndpointHashBuckets, - offsetof(TCPConnection, fEndpointHashNext), + offsetof(TCPEndpoint, fEndpointHashNext), &_EndpointCompare, &_EndpointHash); recursive_lock_init(&fLock, "endpoint manager"); @@ -85,19 +85,19 @@ EndpointManager::InitCheck() const Returns the endpoint matching the connection. You must hold the manager's lock when calling this method. */ -TCPConnection * +TCPEndpoint * EndpointManager::_LookupConnection(sockaddr *local, sockaddr *peer) { connection_key key; key.local = local; key.peer = peer; - return (TCPConnection *)hash_lookup(fConnectionHash, &key); + return (TCPEndpoint *)hash_lookup(fConnectionHash, &key); } status_t -EndpointManager::_RemoveConnection(TCPConnection *endpoint) +EndpointManager::_RemoveConnection(TCPEndpoint *endpoint) { RecursiveLocker locker(&fLock); return hash_remove(fConnectionHash, endpoint); @@ -117,9 +117,9 @@ EndpointManager::_DumpConnections() TRACE(("Active TCP Connections:\n")); - TCPConnection *endpoint; - while ((endpoint = (TCPConnection *)hash_next(fConnectionHash, &iterator)) != NULL) { - TRACE((" TCPConnection %p: local %s, peer %s\n", endpoint, + TCPEndpoint *endpoint; + while ((endpoint = (TCPEndpoint *)hash_next(fConnectionHash, &iterator)) != NULL) { + TRACE((" TCPEndpoint %p: local %s, peer %s\n", endpoint, AddressString(gDomain, (sockaddr *)&endpoint->socket->address, true).Data(), AddressString(gDomain, (sockaddr *)&endpoint->socket->peer, true).Data())); } @@ -129,7 +129,7 @@ EndpointManager::_DumpConnections() status_t -EndpointManager::SetConnection(TCPConnection *endpoint, +EndpointManager::SetConnection(TCPEndpoint *endpoint, const sockaddr *local, const sockaddr *peer, const sockaddr *interfaceLocal) { RecursiveLocker locker(&fLock); @@ -158,10 +158,10 @@ EndpointManager::SetConnection(TCPConnection *endpoint, } -TCPConnection * +TCPEndpoint * EndpointManager::FindConnection(sockaddr *local, sockaddr *peer) { - TCPConnection *endpoint = _LookupConnection(local, peer); + TCPEndpoint *endpoint = _LookupConnection(local, peer); if (endpoint != NULL) { TRACE(("TCP: Received packet corresponds to explicit endpoint %p\n", endpoint)); return endpoint; @@ -199,18 +199,18 @@ EndpointManager::FindConnection(sockaddr *local, sockaddr *peer) // #pragma mark - endpoints -TCPConnection * +TCPEndpoint * EndpointManager::_LookupEndpoint(uint16 port) { endpoint_key key; key.port = port; - return (TCPConnection *)hash_lookup(fEndpointHash, &key); + return (TCPEndpoint *)hash_lookup(fEndpointHash, &key); } status_t -EndpointManager::Bind(TCPConnection *endpoint, sockaddr *address) +EndpointManager::Bind(TCPEndpoint *endpoint, sockaddr *address) { if (gAddressModule->is_empty_address(address, true)) return B_BAD_VALUE; @@ -223,7 +223,7 @@ EndpointManager::Bind(TCPConnection *endpoint, sockaddr *address) RecursiveLocker locker(&fLock); - TCPConnection *first = _LookupEndpoint(port); + TCPEndpoint *first = _LookupEndpoint(port); // If there is already an endpoint bound to that port, SO_REUSEADDR has to be // specified by the new endpoint to be allowed to bind to that same port. @@ -235,7 +235,7 @@ EndpointManager::Bind(TCPConnection *endpoint, sockaddr *address) return EADDRINUSE; if (first != NULL) { - TCPConnection *last = first; + TCPEndpoint *last = first; while (true) { // check if this endpoint binds to a wildcard address if (gAddressModule->is_empty_address((sockaddr *)&last->socket->address, false)) { @@ -263,7 +263,7 @@ EndpointManager::Bind(TCPConnection *endpoint, sockaddr *address) status_t -EndpointManager::BindToEphemeral(TCPConnection *endpoint, sockaddr *address) +EndpointManager::BindToEphemeral(TCPEndpoint *endpoint, sockaddr *address) { RecursiveLocker locker(&fLock); @@ -281,7 +281,7 @@ EndpointManager::BindToEphemeral(TCPConnection *endpoint, sockaddr *address) port = htons(port); - TCPConnection *other = _LookupEndpoint(port); + TCPEndpoint *other = _LookupEndpoint(port); if (other == NULL) { // found a port gAddressModule->set_port((sockaddr *)&endpoint->socket->address, port); @@ -300,7 +300,7 @@ EndpointManager::BindToEphemeral(TCPConnection *endpoint, sockaddr *address) status_t -EndpointManager::Unbind(TCPConnection *endpoint) +EndpointManager::Unbind(TCPEndpoint *endpoint) { if (endpoint == NULL || !endpoint->IsBound()) return B_BAD_VALUE; @@ -310,7 +310,7 @@ EndpointManager::Unbind(TCPConnection *endpoint) if (!endpoint->IsBound()) return B_BAD_VALUE; - TCPConnection *other = _LookupEndpoint(gAddressModule->get_port((sockaddr *)&endpoint->socket->address)); + TCPEndpoint *other = _LookupEndpoint(gAddressModule->get_port((sockaddr *)&endpoint->socket->address)); if (other != endpoint) { // remove endpoint from the list of endpoints with the same port while (other->fEndpointNextWithSamePort != endpoint) { @@ -343,7 +343,7 @@ EndpointManager::Unbind(TCPConnection *endpoint) EndpointManager::_ConnectionCompare(void *_endpoint, const void *_key) { const connection_key *key = (connection_key *)_key; - TCPConnection *endpoint = (TCPConnection *)_endpoint; + TCPEndpoint *endpoint = (TCPEndpoint *)_endpoint; if (gAddressModule->equal_addresses_and_ports(key->local, (sockaddr *)&endpoint->socket->address) @@ -362,7 +362,7 @@ EndpointManager::_ConnectionHash(void *_endpoint, const void *_key, uint32 range const sockaddr *peer; if (_endpoint != NULL) { - TCPConnection *endpoint = (TCPConnection *)_endpoint; + TCPEndpoint *endpoint = (TCPEndpoint *)_endpoint; local = (sockaddr *)&endpoint->socket->address; peer = (sockaddr *)&endpoint->socket->peer; } else { @@ -379,7 +379,7 @@ EndpointManager::_ConnectionHash(void *_endpoint, const void *_key, uint32 range EndpointManager::_EndpointCompare(void *_endpoint, const void *_key) { const endpoint_key *key = (endpoint_key *)_key; - TCPConnection *endpoint = (TCPConnection *)_endpoint; + TCPEndpoint *endpoint = (TCPEndpoint *)_endpoint; return gAddressModule->get_port((sockaddr *)&endpoint->socket->address) == key->port ? 0 : 1; @@ -390,7 +390,7 @@ EndpointManager::_EndpointCompare(void *_endpoint, const void *_key) EndpointManager::_EndpointHash(void *_endpoint, const void *_key, uint32 range) { if (_endpoint != NULL) { - TCPConnection *endpoint = (TCPConnection *)_endpoint; + TCPEndpoint *endpoint = (TCPEndpoint *)_endpoint; return gAddressModule->get_port((sockaddr *)&endpoint->socket->address) % range; } diff --git a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h index 6adbc90b71..aaace63e5b 100644 --- a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h +++ b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h @@ -15,7 +15,7 @@ #include -class TCPConnection; +class TCPEndpoint; class EndpointManager { public: @@ -26,18 +26,18 @@ class EndpointManager { recursive_lock *Locker() { return &fLock; } - status_t SetConnection(TCPConnection *endpoint, const sockaddr *local, + status_t SetConnection(TCPEndpoint *endpoint, const sockaddr *local, const sockaddr *peer, const sockaddr *interfaceLocal); - TCPConnection *FindConnection(sockaddr *local, sockaddr *peer); + TCPEndpoint *FindConnection(sockaddr *local, sockaddr *peer); - status_t Bind(TCPConnection *endpoint, sockaddr *address); - status_t BindToEphemeral(TCPConnection *endpoint, sockaddr *address); - status_t Unbind(TCPConnection *endpoint); + status_t Bind(TCPEndpoint *endpoint, sockaddr *address); + status_t BindToEphemeral(TCPEndpoint *endpoint, sockaddr *address); + status_t Unbind(TCPEndpoint *endpoint); private: - TCPConnection *_LookupConnection(sockaddr *local, sockaddr *peer); - status_t _RemoveConnection(TCPConnection *endpoint); - TCPConnection *_LookupEndpoint(uint16 port); + TCPEndpoint *_LookupConnection(sockaddr *local, sockaddr *peer); + status_t _RemoveConnection(TCPEndpoint *endpoint); + TCPEndpoint *_LookupEndpoint(uint16 port); void _DumpConnections(); static int _ConnectionCompare(void *_endpoint, const void *_key); diff --git a/src/add-ons/kernel/network/protocols/tcp/Jamfile b/src/add-ons/kernel/network/protocols/tcp/Jamfile index d5862f5f20..da555d5284 100644 --- a/src/add-ons/kernel/network/protocols/tcp/Jamfile +++ b/src/add-ons/kernel/network/protocols/tcp/Jamfile @@ -14,7 +14,7 @@ UsePrivateHeaders kernel net ; KernelAddon tcp : tcp.cpp - TCPConnection.cpp + TCPEndpoint.cpp BufferQueue.cpp EndpointManager.cpp ; diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPConnection.cpp b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp similarity index 89% rename from src/add-ons/kernel/network/protocols/tcp/TCPConnection.cpp rename to src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp index 3a67adb7d2..ed5d07918d 100644 --- a/src/add-ons/kernel/network/protocols/tcp/TCPConnection.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp @@ -8,7 +8,7 @@ */ -#include "TCPConnection.h" +#include "TCPEndpoint.h" #include "EndpointManager.h" #include @@ -58,7 +58,7 @@ enum { }; -TCPConnection::TCPConnection(net_socket *socket) +TCPEndpoint::TCPEndpoint(net_socket *socket) : fOptions(0), fSendWindowShift(0), @@ -91,15 +91,15 @@ TCPConnection::TCPConnection(net_socket *socket) fSendLock = create_sem(0, "tcp send"); fReceiveLock = create_sem(0, "tcp receive"); - gStackModule->init_timer(&fPersistTimer, TCPConnection::_PersistTimer, this); - gStackModule->init_timer(&fRetransmitTimer, TCPConnection::_RetransmitTimer, this); + gStackModule->init_timer(&fPersistTimer, TCPEndpoint::_PersistTimer, this); + gStackModule->init_timer(&fRetransmitTimer, TCPEndpoint::_RetransmitTimer, this); gStackModule->init_timer(&fDelayedAcknowledgeTimer, - TCPConnection::_DelayedAcknowledgeTimer, this); - gStackModule->init_timer(&fTimeWaitTimer, TCPConnection::_TimeWaitTimer, this); + TCPEndpoint::_DelayedAcknowledgeTimer, this); + gStackModule->init_timer(&fTimeWaitTimer, TCPEndpoint::_TimeWaitTimer, this); } -TCPConnection::~TCPConnection() +TCPEndpoint::~TCPEndpoint() { gStackModule->cancel_timer(&fRetransmitTimer); gStackModule->cancel_timer(&fPersistTimer); @@ -117,7 +117,7 @@ TCPConnection::~TCPConnection() status_t -TCPConnection::InitCheck() const +TCPEndpoint::InitCheck() const { if (fLock.sem < B_OK) return fLock.sem; @@ -134,7 +134,7 @@ TCPConnection::InitCheck() const status_t -TCPConnection::Open() +TCPEndpoint::Open() { TRACE(("%p.Open()\n", this)); // nothing to do here... @@ -143,7 +143,7 @@ TCPConnection::Open() status_t -TCPConnection::Close() +TCPEndpoint::Close() { TRACE(("TCP:%p.Close()\n", this)); RecursiveLocker lock(fLock); @@ -178,7 +178,7 @@ TCPConnection::Close() status_t -TCPConnection::Free() +TCPEndpoint::Free() { TRACE(("TCP:%p.Free()\n", this)); @@ -196,7 +196,7 @@ TCPConnection::Free() until the connection has been established or refused. */ status_t -TCPConnection::Connect(const struct sockaddr *address) +TCPEndpoint::Connect(const struct sockaddr *address) { TRACE(("TCP:%p.Connect() on address %s\n", this, AddressString(gDomain, address, true).Data())); @@ -209,7 +209,7 @@ TCPConnection::Connect(const struct sockaddr *address) TRACE((" TCP: Connect(): in state %d\n", fState)); // Can only call connect() from CLOSED or LISTEN states - // otherwise connection is considered already connected + // otherwise endpoint is considered already connected if (fState == LISTEN) { // this socket is about to connect; remove pending connections in the backlog gSocketModule->set_max_backlog(socket, 0); @@ -275,7 +275,7 @@ TCPConnection::Connect(const struct sockaddr *address) status_t -TCPConnection::Accept(struct net_socket **_acceptedSocket) +TCPEndpoint::Accept(struct net_socket **_acceptedSocket) { TRACE(("TCP:%p.Accept()\n", this)); @@ -296,7 +296,7 @@ TCPConnection::Accept(struct net_socket **_acceptedSocket) status_t -TCPConnection::Bind(sockaddr *address) +TCPEndpoint::Bind(sockaddr *address) { TRACE(("TCP:%p.Bind() on address %s\n", this, AddressString(gDomain, address, true).Data())); @@ -321,7 +321,7 @@ TCPConnection::Bind(sockaddr *address) status_t -TCPConnection::Unbind(struct sockaddr *address) +TCPEndpoint::Unbind(struct sockaddr *address) { TRACE(("TCP:%p.Unbind()\n", this)); @@ -331,7 +331,7 @@ TCPConnection::Unbind(struct sockaddr *address) status_t -TCPConnection::Listen(int count) +TCPEndpoint::Listen(int count) { TRACE(("TCP:%p.Listen()\n", this)); @@ -349,7 +349,7 @@ TCPConnection::Listen(int count) status_t -TCPConnection::Shutdown(int direction) +TCPEndpoint::Shutdown(int direction) { TRACE(("TCP:%p.Shutdown()\n", this)); // TODO: implement shutdown! @@ -361,7 +361,7 @@ TCPConnection::Shutdown(int direction) Puts data contained in \a buffer into send buffer */ status_t -TCPConnection::SendData(net_buffer *buffer) +TCPEndpoint::SendData(net_buffer *buffer) { TRACE(("TCP:%p.SendData()\n", this)); @@ -422,7 +422,7 @@ TCPConnection::SendData(net_buffer *buffer) size_t -TCPConnection::SendAvailable() +TCPEndpoint::SendAvailable() { TRACE(("TCP:%p.SendAvailable()\n", this)); @@ -432,7 +432,7 @@ TCPConnection::SendAvailable() status_t -TCPConnection::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer) +TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer) { TRACE(("TCP:%p.ReadData()\n", this)); @@ -466,7 +466,7 @@ TCPConnection::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer) size_t -TCPConnection::ReadAvailable() +TCPEndpoint::ReadAvailable() { TRACE(("TCP:%p.ReadAvailable()\n", this)); @@ -479,14 +479,14 @@ TCPConnection::ReadAvailable() bool -TCPConnection::IsBound() const +TCPEndpoint::IsBound() const { return !gAddressModule->is_empty_address((sockaddr *)&socket->address, true); } status_t -TCPConnection::DelayedAcknowledge() +TCPEndpoint::DelayedAcknowledge() { // if the timer is already running, and there is still more than // half of the receive window free, just wait for the timer to expire @@ -506,28 +506,28 @@ TCPConnection::DelayedAcknowledge() status_t -TCPConnection::SendAcknowledge() +TCPEndpoint::SendAcknowledge() { return _SendQueued(true); } void -TCPConnection::_StartPersistTimer() +TCPEndpoint::_StartPersistTimer() { gStackModule->set_timer(&fPersistTimer, 1000000LL); } void -TCPConnection::_EnterTimeWait() +TCPEndpoint::_EnterTimeWait() { gStackModule->set_timer(&fTimeWaitTimer, TCP_MAX_SEGMENT_LIFETIME << 1); } status_t -TCPConnection::UpdateTimeWait() +TCPEndpoint::UpdateTimeWait() { return B_OK; } @@ -537,7 +537,7 @@ TCPConnection::UpdateTimeWait() int32 -TCPConnection::ListenReceive(tcp_segment_header &segment, net_buffer *buffer) +TCPEndpoint::ListenReceive(tcp_segment_header &segment, net_buffer *buffer) { // Essentially, we accept only TCP_FLAG_SYNCHRONIZE in this state, // but the error behaviour differs @@ -550,7 +550,7 @@ TCPConnection::ListenReceive(tcp_segment_header &segment, net_buffer *buffer) // TODO: drop broadcast/multicast - // spawn new connection for accept() + // spawn new endpoint for accept() net_socket *newSocket; if (gSocketModule->spawn_pending_socket(socket, &newSocket) < B_OK) return DROP; @@ -560,55 +560,55 @@ TCPConnection::ListenReceive(tcp_segment_header &segment, net_buffer *buffer) gAddressModule->set_to((sockaddr *)&newSocket->peer, (sockaddr *)&buffer->source); - TCPConnection *connection = (TCPConnection *)newSocket->first_protocol; + TCPEndpoint *endpoint = (TCPEndpoint *)newSocket->first_protocol; // TODO: proper error handling! - connection->fRoute = gDatalinkModule->get_route(gDomain, + endpoint->fRoute = gDatalinkModule->get_route(gDomain, (sockaddr *)&newSocket->peer); - if (connection->fRoute == NULL) + if (endpoint->fRoute == NULL) return DROP; - if (gEndpointManager->SetConnection(connection, (sockaddr *)&buffer->destination, + if (gEndpointManager->SetConnection(endpoint, (sockaddr *)&buffer->destination, (sockaddr *)&buffer->source, NULL) < B_OK) return DROP; - connection->fInitialReceiveSequence = segment.sequence; - connection->fReceiveQueue.SetInitialSequence(segment.sequence + 1); - connection->fState = SYNCHRONIZE_RECEIVED; - connection->fAcceptSemaphore = fAcceptSemaphore; - connection->fReceiveMaxSegmentSize = connection->fRoute->mtu - 40; + endpoint->fInitialReceiveSequence = segment.sequence; + endpoint->fReceiveQueue.SetInitialSequence(segment.sequence + 1); + endpoint->fState = SYNCHRONIZE_RECEIVED; + endpoint->fAcceptSemaphore = fAcceptSemaphore; + endpoint->fReceiveMaxSegmentSize = endpoint->fRoute->mtu - 40; // 40 bytes for IP and TCP header without any options // TODO: make this depending on the RTF_LOCAL flag? - connection->fReceiveNext = segment.sequence + 1; + endpoint->fReceiveNext = segment.sequence + 1; // account for the extra sequence number for the synchronization - connection->fSendNext = connection->fInitialSendSequence; - connection->fSendUnacknowledged = connection->fSendNext; - connection->fSendMax = connection->fSendNext; + endpoint->fSendNext = endpoint->fInitialSendSequence; + endpoint->fSendUnacknowledged = endpoint->fSendNext; + endpoint->fSendMax = endpoint->fSendNext; // set options if ((fOptions & TCP_NOOPT) == 0) { if (segment.max_segment_size > 0) - connection->fSendMaxSegmentSize = segment.max_segment_size; + endpoint->fSendMaxSegmentSize = segment.max_segment_size; else - connection->fReceiveMaxSegmentSize = TCP_DEFAULT_MAX_SEGMENT_SIZE; + endpoint->fReceiveMaxSegmentSize = TCP_DEFAULT_MAX_SEGMENT_SIZE; if (segment.has_window_shift) { - connection->fFlags |= FLAG_OPTION_WINDOW_SHIFT; - connection->fSendWindowShift = segment.window_shift; + endpoint->fFlags |= FLAG_OPTION_WINDOW_SHIFT; + endpoint->fSendWindowShift = segment.window_shift; } else { - connection->fFlags &= ~FLAG_OPTION_WINDOW_SHIFT; - connection->fReceiveWindowShift = 0; + endpoint->fFlags &= ~FLAG_OPTION_WINDOW_SHIFT; + endpoint->fReceiveWindowShift = 0; } } // send SYN+ACK - //benaphore_lock(&connection->fSendLock); - status_t status = connection->_SendQueued(); - //benaphore_unlock(&connection->fSendLock); + //benaphore_lock(&endpoint->fSendLock); + status_t status = endpoint->_SendQueued(); + //benaphore_unlock(&endpoint->fSendLock); - connection->fInitialSendSequence = fSendNext; - connection->fSendQueue.SetInitialSequence(fSendNext); + endpoint->fInitialSendSequence = fSendNext; + endpoint->fSendQueue.SetInitialSequence(fSendNext); if (status < B_OK) return DROP; @@ -616,13 +616,13 @@ TCPConnection::ListenReceive(tcp_segment_header &segment, net_buffer *buffer) segment.flags &= ~TCP_FLAG_SYNCHRONIZE; // we handled this flag now, it must not be set for further processing - return connection->Receive(segment, buffer); + return endpoint->Receive(segment, buffer); // TODO: here, the ack/delayed ack call will be made on the parent socket! } int32 -TCPConnection::SynchronizeSentReceive(tcp_segment_header &segment, net_buffer *buffer) +TCPEndpoint::SynchronizeSentReceive(tcp_segment_header &segment, net_buffer *buffer) { if ((segment.flags & TCP_FLAG_ACKNOWLEDGE) != 0 && (fInitialSendSequence >= segment.acknowledge @@ -683,7 +683,7 @@ TCPConnection::SynchronizeSentReceive(tcp_segment_header &segment, net_buffer *b int32 -TCPConnection::Receive(tcp_segment_header &segment, net_buffer *buffer) +TCPEndpoint::Receive(tcp_segment_header &segment, net_buffer *buffer) { TRACE(("TCP:%p.ReceiveData(): Connection in state %d received packet %p with flags 0x%x, seq %lu, ack %lu!\n", this, fState, buffer, segment.flags, segment.sequence, segment.acknowledge)); @@ -841,7 +841,7 @@ TCPConnection::Receive(tcp_segment_header &segment, net_buffer *buffer) if (fSendMax == segment.acknowledge) { // there is no outstanding data to be acknowledged // TODO: if the transmit timer function is already waiting - // to acquire this connection's lock, we should stop it anyway + // to acquire this endpoint's lock, we should stop it anyway gStackModule->cancel_timer(&fRetransmitTimer); } else { // TODO: set retransmit timer correctly @@ -945,7 +945,7 @@ TCPConnection::Receive(tcp_segment_header &segment, net_buffer *buffer) it couldn't send all the data. */ inline uint8 -TCPConnection::_CurrentFlags() +TCPEndpoint::_CurrentFlags() { switch (fState) { case CLOSED: @@ -976,7 +976,7 @@ TCPConnection::_CurrentFlags() inline bool -TCPConnection::_ShouldSendSegment(tcp_segment_header &segment, uint32 length, +TCPEndpoint::_ShouldSendSegment(tcp_segment_header &segment, uint32 length, bool outstandingAcknowledge) { if (length > 0) { @@ -1019,7 +1019,7 @@ TCPConnection::_ShouldSendSegment(tcp_segment_header &segment, uint32 length, specific flags that need to be sent. */ status_t -TCPConnection::_SendQueued(bool force) +TCPEndpoint::_SendQueued(bool force) { if (fRoute == NULL) return B_ERROR; @@ -1160,9 +1160,9 @@ TCPConnection::_SendQueued(bool force) /*static*/ void -TCPConnection::_RetransmitTimer(net_timer *timer, void *data) +TCPEndpoint::_RetransmitTimer(net_timer *timer, void *data) { - TCPConnection *connection = (TCPConnection *)data; + TCPEndpoint *connection = (TCPEndpoint *)data; RecursiveLocker locker(connection->Lock()); @@ -1173,9 +1173,9 @@ TCPConnection::_RetransmitTimer(net_timer *timer, void *data) /*static*/ void -TCPConnection::_PersistTimer(net_timer *timer, void *data) +TCPEndpoint::_PersistTimer(net_timer *timer, void *data) { - TCPConnection *connection = (TCPConnection *)data; + TCPEndpoint *connection = (TCPEndpoint *)data; RecursiveLocker locker(connection->Lock()); connection->_SendQueued(true); @@ -1183,9 +1183,9 @@ TCPConnection::_PersistTimer(net_timer *timer, void *data) /*static*/ void -TCPConnection::_DelayedAcknowledgeTimer(struct net_timer *timer, void *data) +TCPEndpoint::_DelayedAcknowledgeTimer(struct net_timer *timer, void *data) { - TCPConnection *connection = (TCPConnection *)data; + TCPEndpoint *connection = (TCPEndpoint *)data; RecursiveLocker locker(connection->Lock()); connection->_SendQueued(true); @@ -1193,9 +1193,9 @@ TCPConnection::_DelayedAcknowledgeTimer(struct net_timer *timer, void *data) /*static*/ void -TCPConnection::_TimeWaitTimer(struct net_timer *timer, void *data) +TCPEndpoint::_TimeWaitTimer(struct net_timer *timer, void *data) { - TCPConnection *connection = (TCPConnection *)data; + TCPEndpoint *connection = (TCPEndpoint *)data; RecursiveLocker locker(connection->Lock()); gSocketModule->delete_socket(connection->socket); diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPConnection.h b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h similarity index 91% rename from src/add-ons/kernel/network/protocols/tcp/TCPConnection.h rename to src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h index 1d2a53c447..bfc54b0bf3 100644 --- a/src/add-ons/kernel/network/protocols/tcp/TCPConnection.h +++ b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h @@ -6,8 +6,8 @@ * Andrew Galante, haiku.galante@gmail.com * Axel Dörfler, axeld@pinc-software.de */ -#ifndef TCP_CONNECTION_H -#define TCP_CONNECTION_H +#ifndef TCP_ENDPOINT_H +#define TCP_ENDPOINT_H #include "tcp.h" @@ -22,10 +22,10 @@ class EndpointManager; -class TCPConnection : public net_protocol { +class TCPEndpoint : public net_protocol { public: - TCPConnection(net_socket *socket); - ~TCPConnection(); + TCPEndpoint(net_socket *socket); + ~TCPEndpoint(); status_t InitCheck() const; @@ -71,9 +71,9 @@ class TCPConnection : public net_protocol { static void _PersistTimer(net_timer *timer, void *data); static void _DelayedAcknowledgeTimer(net_timer *timer, void *data); - TCPConnection *fConnectionHashNext; - TCPConnection *fEndpointHashNext; - TCPConnection *fEndpointNextWithSamePort; + TCPEndpoint *fConnectionHashNext; + TCPEndpoint *fEndpointHashNext; + TCPEndpoint *fEndpointNextWithSamePort; recursive_lock fLock; sem_id fReceiveLock; @@ -128,4 +128,4 @@ class TCPConnection : public net_protocol { net_timer fTimeWaitTimer; }; -#endif // TCP_CONNECTION_H +#endif // TCP_ENDPOINT_H diff --git a/src/add-ons/kernel/network/protocols/tcp/tcp.cpp b/src/add-ons/kernel/network/protocols/tcp/tcp.cpp index 94c1cda899..11fbecea32 100644 --- a/src/add-ons/kernel/network/protocols/tcp/tcp.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/tcp.cpp @@ -9,7 +9,7 @@ #include "EndpointManager.h" -#include "TCPConnection.h" +#include "TCPEndpoint.h" #include @@ -265,7 +265,7 @@ reply_with_reset(tcp_segment_header &segment, net_buffer *buffer) net_protocol * tcp_init_protocol(net_socket *socket) { - TCPConnection *protocol = new (std::nothrow) TCPConnection(socket); + TCPEndpoint *protocol = new (std::nothrow) TCPEndpoint(socket); if (protocol == NULL) return NULL; @@ -274,7 +274,7 @@ tcp_init_protocol(net_socket *socket) return NULL; } - TRACE(("Creating new TCPConnection: %p\n", protocol)); + TRACE(("Creating new TCPEndpoint: %p\n", protocol)); socket->protocol = IPPROTO_TCP; return protocol; } @@ -283,8 +283,8 @@ tcp_init_protocol(net_socket *socket) status_t tcp_uninit_protocol(net_protocol *protocol) { - TRACE(("Deleting TCPConnection: %p\n", protocol)); - delete (TCPConnection *)protocol; + TRACE(("Deleting TCPEndpoint: %p\n", protocol)); + delete (TCPEndpoint *)protocol; return B_OK; } @@ -295,35 +295,35 @@ tcp_open(net_protocol *protocol) if (gDomain == NULL && set_domain() != B_OK) return B_ERROR; - return ((TCPConnection *)protocol)->Open(); + return ((TCPEndpoint *)protocol)->Open(); } status_t tcp_close(net_protocol *protocol) { - return ((TCPConnection *)protocol)->Close(); + return ((TCPEndpoint *)protocol)->Close(); } status_t tcp_free(net_protocol *protocol) { - return ((TCPConnection *)protocol)->Free(); + return ((TCPEndpoint *)protocol)->Free(); } status_t tcp_connect(net_protocol *protocol, const struct sockaddr *address) { - return ((TCPConnection *)protocol)->Connect(address); + return ((TCPEndpoint *)protocol)->Connect(address); } status_t tcp_accept(net_protocol *protocol, struct net_socket **_acceptedSocket) { - return ((TCPConnection *)protocol)->Accept(_acceptedSocket); + return ((TCPEndpoint *)protocol)->Accept(_acceptedSocket); } @@ -339,35 +339,35 @@ tcp_control(net_protocol *protocol, int level, int option, void *value, status_t tcp_bind(net_protocol *protocol, struct sockaddr *address) { - return ((TCPConnection *)protocol)->Bind(address); + return ((TCPEndpoint *)protocol)->Bind(address); } status_t tcp_unbind(net_protocol *protocol, struct sockaddr *address) { - return ((TCPConnection *)protocol)->Unbind(address); + return ((TCPEndpoint *)protocol)->Unbind(address); } status_t tcp_listen(net_protocol *protocol, int count) { - return ((TCPConnection *)protocol)->Listen(count); + return ((TCPEndpoint *)protocol)->Listen(count); } status_t tcp_shutdown(net_protocol *protocol, int direction) { - return ((TCPConnection *)protocol)->Shutdown(direction); + return ((TCPEndpoint *)protocol)->Shutdown(direction); } status_t tcp_send_data(net_protocol *protocol, net_buffer *buffer) { - return ((TCPConnection *)protocol)->SendData(buffer); + return ((TCPEndpoint *)protocol)->SendData(buffer); } @@ -383,7 +383,7 @@ tcp_send_routed_data(net_protocol *protocol, struct net_route *route, ssize_t tcp_send_avail(net_protocol *protocol) { - return ((TCPConnection *)protocol)->SendAvailable(); + return ((TCPEndpoint *)protocol)->SendAvailable(); } @@ -391,14 +391,14 @@ status_t tcp_read_data(net_protocol *protocol, size_t numBytes, uint32 flags, net_buffer **_buffer) { - return ((TCPConnection *)protocol)->ReadData(numBytes, flags, _buffer); + return ((TCPEndpoint *)protocol)->ReadData(numBytes, flags, _buffer); } ssize_t tcp_read_avail(net_protocol *protocol) { - return ((TCPConnection *)protocol)->ReadAvailable(); + return ((TCPEndpoint *)protocol)->ReadAvailable(); } @@ -470,24 +470,24 @@ tcp_receive_data(net_buffer *buffer) RecursiveLocker locker(gEndpointManager->Locker()); int32 segmentAction = DROP; - TCPConnection *connection = gEndpointManager->FindConnection( + TCPEndpoint *endpoint = gEndpointManager->FindConnection( (struct sockaddr *)&buffer->destination, (struct sockaddr *)&buffer->source); - if (connection != NULL) { - RecursiveLocker locker(connection->Lock()); + if (endpoint != NULL) { + RecursiveLocker locker(endpoint->Lock()); - switch (connection->State()) { + switch (endpoint->State()) { case TIME_WAIT: segmentAction |= IMMEDIATE_ACKNOWLEDGE; case CLOSED: - connection->UpdateTimeWait(); + endpoint->UpdateTimeWait(); break; case LISTEN: - segmentAction = connection->ListenReceive(segment, buffer); + segmentAction = endpoint->ListenReceive(segment, buffer); break; case SYNCHRONIZE_SENT: - segmentAction = connection->SynchronizeSentReceive(segment, buffer); + segmentAction = endpoint->SynchronizeSentReceive(segment, buffer); break; case SYNCHRONIZE_RECEIVED: @@ -497,15 +497,15 @@ tcp_receive_data(net_buffer *buffer) case FINISH_SENT: case FINISH_ACKNOWLEDGED: case CLOSING: - segmentAction = connection->Receive(segment, buffer); + segmentAction = endpoint->Receive(segment, buffer); break; } // process acknowledge action as asked for by the *Receive() method if (segmentAction & IMMEDIATE_ACKNOWLEDGE) - connection->SendAcknowledge(); + endpoint->SendAcknowledge(); else if (segmentAction & ACKNOWLEDGE) - connection->DelayedAcknowledge(); + endpoint->DelayedAcknowledge(); } else if ((segment.flags & TCP_FLAG_RESET) == 0) segmentAction = DROP | RESET; diff --git a/src/tests/kits/net/Jamfile b/src/tests/kits/net/Jamfile index eb170f3d3b..d6dbde6a17 100644 --- a/src/tests/kits/net/Jamfile +++ b/src/tests/kits/net/Jamfile @@ -34,7 +34,7 @@ SimpleTest tcp_tester : # tcp tcp.cpp - TCPConnection.cpp + TCPEndpoint.cpp BufferQueue.cpp EndpointManager.cpp @@ -46,7 +46,7 @@ SimpleTest tcp_tester : ; SEARCH on [ FGristFiles - tcp.cpp TCPConnection.cpp BufferQueue.cpp EndpointManager.cpp + tcp.cpp TCPEndpoint.cpp BufferQueue.cpp EndpointManager.cpp ] = [ FDirName $(HAIKU_TOP) src add-ons kernel network protocols tcp ] ; SEARCH on [ FGristFiles