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