nfs4: Use more meaningful names in Connection and RPCServer
This commit is contained in:
@@ -24,41 +24,41 @@
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ServerAddress::operator==(const ServerAddress& x)
|
ServerAddress::operator==(const ServerAddress& address)
|
||||||
{
|
{
|
||||||
return fAddress == x.fAddress && fPort == x.fPort
|
return fAddress == address.fAddress && fPort == address.fPort
|
||||||
&& fProtocol == x.fProtocol;
|
&& fProtocol == address.fProtocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ServerAddress::operator<(const ServerAddress& x)
|
ServerAddress::operator<(const ServerAddress& address)
|
||||||
{
|
{
|
||||||
return fAddress < x.fAddress ||
|
return fAddress < address.fAddress ||
|
||||||
(fAddress == x.fAddress && fPort < x.fPort) ||
|
(fAddress == address.fAddress && fPort < address.fPort) ||
|
||||||
(fAddress == x.fAddress && fPort == x.fPort &&
|
(fAddress == address.fAddress && fPort == address.fPort &&
|
||||||
fProtocol < x.fProtocol);
|
fProtocol < address.fProtocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ServerAddress&
|
ServerAddress&
|
||||||
ServerAddress::operator=(const ServerAddress& x)
|
ServerAddress::operator=(const ServerAddress& address)
|
||||||
{
|
{
|
||||||
fAddress = x.fAddress;
|
fAddress = address.fAddress;
|
||||||
fPort = x.fPort;
|
fPort = address.fPort;
|
||||||
fProtocol = x.fProtocol;
|
fProtocol = address.fProtocol;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ServerAddress::ResolveName(const char* name, ServerAddress* addr)
|
ServerAddress::ResolveName(const char* name, ServerAddress* address)
|
||||||
{
|
{
|
||||||
addr->fPort = 2049;
|
address->fPort = 2049;
|
||||||
addr->fProtocol = IPPROTO_UDP;
|
address->fProtocol = IPPROTO_UDP;
|
||||||
|
|
||||||
struct in_addr iaddr;
|
struct in_addr iaddr;
|
||||||
if (inet_aton(name, &iaddr) != 0) {
|
if (inet_aton(name, &iaddr) != 0) {
|
||||||
addr->fAddress = ntohl(iaddr.s_addr);
|
address->fAddress = ntohl(iaddr.s_addr);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +70,10 @@ ServerAddress::ResolveName(const char* name, ServerAddress* addr)
|
|||||||
addrinfo* current = ai;
|
addrinfo* current = ai;
|
||||||
while (current != NULL) {
|
while (current != NULL) {
|
||||||
if (current->ai_family == AF_INET) {
|
if (current->ai_family == AF_INET) {
|
||||||
sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(current->ai_addr);
|
sockaddr_in* sin =
|
||||||
|
reinterpret_cast<sockaddr_in*>(current->ai_addr);
|
||||||
|
|
||||||
addr->fAddress = ntohl(sin->sin_addr.s_addr);
|
address->fAddress = ntohl(sin->sin_addr.s_addr);
|
||||||
|
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -86,52 +87,52 @@ ServerAddress::ResolveName(const char* name, ServerAddress* addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Connection::Connection(const sockaddr_in& addr, int proto)
|
Connection::Connection(const sockaddr_in& address, int protocol)
|
||||||
:
|
:
|
||||||
fWaitCancel(create_sem(0, NULL)),
|
fWaitCancel(create_sem(0, NULL)),
|
||||||
fSock(-1),
|
fSocket(-1),
|
||||||
fProtocol(proto),
|
fProtocol(protocol),
|
||||||
fServerAddress(addr)
|
fServerAddress(address)
|
||||||
{
|
{
|
||||||
mutex_init(&fSockLock, NULL);
|
mutex_init(&fSocketLock, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConnectionStream::ConnectionStream(const sockaddr_in& addr, int proto)
|
ConnectionStream::ConnectionStream(const sockaddr_in& address, int protocol)
|
||||||
:
|
:
|
||||||
Connection(addr, proto)
|
Connection(address, protocol)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConnectionPacket::ConnectionPacket(const sockaddr_in& addr, int proto)
|
ConnectionPacket::ConnectionPacket(const sockaddr_in& address, int protocol)
|
||||||
:
|
:
|
||||||
Connection(addr, proto)
|
Connection(address, protocol)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Connection::~Connection()
|
Connection::~Connection()
|
||||||
{
|
{
|
||||||
if (fSock != -1)
|
if (fSocket != -1)
|
||||||
close(fSock);
|
close(fSocket);
|
||||||
mutex_destroy(&fSockLock);
|
mutex_destroy(&fSocketLock);
|
||||||
delete_sem(fWaitCancel);
|
delete_sem(fWaitCancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Connection::GetLocalID(ServerAddress* addr)
|
Connection::GetLocalAddress(ServerAddress* address)
|
||||||
{
|
{
|
||||||
struct sockaddr_in saddr;
|
struct sockaddr_in saddr;
|
||||||
socklen_t slen = sizeof(addr);
|
socklen_t slen = sizeof(saddr);
|
||||||
status_t result = getsockname(fSock, (struct sockaddr*)&saddr, &slen);
|
status_t result = getsockname(fSocket, (struct sockaddr*)&saddr, &slen);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
addr->fProtocol = fProtocol;
|
address->fProtocol = fProtocol;
|
||||||
addr->fPort = ntohs(saddr.sin_port);
|
address->fPort = ntohs(saddr.sin_port);
|
||||||
addr->fAddress = ntohl(saddr.sin_addr.s_addr);
|
address->fAddress = ntohl(saddr.sin_addr.s_addr);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -152,12 +153,12 @@ ConnectionStream::Send(const void* buffer, uint32 size)
|
|||||||
// More than one threads may send data and ksend is allowed to send partial
|
// More than one threads may send data and ksend is allowed to send partial
|
||||||
// data. Need a lock here.
|
// data. Need a lock here.
|
||||||
uint32 sent = 0;
|
uint32 sent = 0;
|
||||||
mutex_lock(&fSockLock);
|
mutex_lock(&fSocketLock);
|
||||||
do {
|
do {
|
||||||
result = send(fSock, buf + sent, size + sizeof(uint32) - sent, 0);
|
result = send(fSocket, buf + sent, size + sizeof(uint32) - sent, 0);
|
||||||
sent += result;
|
sent += result;
|
||||||
} while (result > 0 && sent < size + sizeof(uint32));
|
} while (result > 0 && sent < size + sizeof(uint32));
|
||||||
mutex_unlock(&fSockLock);
|
mutex_unlock(&fSocketLock);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
result = errno;
|
result = errno;
|
||||||
free(buf);
|
free(buf);
|
||||||
@@ -176,7 +177,7 @@ status_t
|
|||||||
ConnectionPacket::Send(const void* buffer, uint32 size)
|
ConnectionPacket::Send(const void* buffer, uint32 size)
|
||||||
{
|
{
|
||||||
// send on DGRAM sockets is atomic. No need to lock.
|
// send on DGRAM sockets is atomic. No need to lock.
|
||||||
status_t result = send(fSock, buffer, size, 0);
|
status_t result = send(fSocket, buffer, size, 0);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
@@ -185,7 +186,7 @@ ConnectionPacket::Send(const void* buffer, uint32 size)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ConnectionStream::Receive(void** pbuffer, uint32* psize)
|
ConnectionStream::Receive(void** _buffer, uint32* _size)
|
||||||
{
|
{
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
@@ -200,7 +201,7 @@ ConnectionStream::Receive(void** pbuffer, uint32* psize)
|
|||||||
object[0].type = B_OBJECT_TYPE_SEMAPHORE;
|
object[0].type = B_OBJECT_TYPE_SEMAPHORE;
|
||||||
object[0].events = B_EVENT_ACQUIRE_SEMAPHORE;
|
object[0].events = B_EVENT_ACQUIRE_SEMAPHORE;
|
||||||
|
|
||||||
object[1].object = fSock;
|
object[1].object = fSocket;
|
||||||
object[1].type = B_OBJECT_TYPE_FD;
|
object[1].type = B_OBJECT_TYPE_FD;
|
||||||
object[1].events = B_EVENT_READ;
|
object[1].events = B_EVENT_READ;
|
||||||
|
|
||||||
@@ -216,7 +217,7 @@ ConnectionStream::Receive(void** pbuffer, uint32* psize)
|
|||||||
// There is only one listener thread per connection. No need to lock.
|
// There is only one listener thread per connection. No need to lock.
|
||||||
uint32 received = 0;
|
uint32 received = 0;
|
||||||
do {
|
do {
|
||||||
result = recv(fSock, &record_size + received,
|
result = recv(fSocket, &record_size + received,
|
||||||
sizeof(record_size) - received, 0);
|
sizeof(record_size) - received, 0);
|
||||||
received += result;
|
received += result;
|
||||||
} while (result > 0 && received < sizeof(record_size));
|
} while (result > 0 && received < sizeof(record_size));
|
||||||
@@ -242,7 +243,7 @@ ConnectionStream::Receive(void** pbuffer, uint32* psize)
|
|||||||
|
|
||||||
received = 0;
|
received = 0;
|
||||||
do {
|
do {
|
||||||
result = recv(fSock, (uint8*)buffer + size + received,
|
result = recv(fSocket, (uint8*)buffer + size + received,
|
||||||
record_size - received, 0);
|
record_size - received, 0);
|
||||||
received += result;
|
received += result;
|
||||||
} while (result > 0 && received < sizeof(record_size));
|
} while (result > 0 && received < sizeof(record_size));
|
||||||
@@ -256,15 +257,15 @@ ConnectionStream::Receive(void** pbuffer, uint32* psize)
|
|||||||
} while (!last_one);
|
} while (!last_one);
|
||||||
|
|
||||||
|
|
||||||
*pbuffer = buffer;
|
*_buffer = buffer;
|
||||||
*psize = size;
|
*_size = size;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ConnectionPacket::Receive(void** pbuffer, uint32* psize)
|
ConnectionPacket::Receive(void** _buffer, uint32* _size)
|
||||||
{
|
{
|
||||||
status_t result;
|
status_t result;
|
||||||
int32 size = MAX_PACKET_SIZE;
|
int32 size = MAX_PACKET_SIZE;
|
||||||
@@ -278,7 +279,7 @@ ConnectionPacket::Receive(void** pbuffer, uint32* psize)
|
|||||||
object[0].type = B_OBJECT_TYPE_SEMAPHORE;
|
object[0].type = B_OBJECT_TYPE_SEMAPHORE;
|
||||||
object[0].events = B_EVENT_ACQUIRE_SEMAPHORE;
|
object[0].events = B_EVENT_ACQUIRE_SEMAPHORE;
|
||||||
|
|
||||||
object[1].object = fSock;
|
object[1].object = fSocket;
|
||||||
object[1].type = B_OBJECT_TYPE_FD;
|
object[1].type = B_OBJECT_TYPE_FD;
|
||||||
object[1].events = B_EVENT_READ;
|
object[1].events = B_EVENT_READ;
|
||||||
|
|
||||||
@@ -294,7 +295,7 @@ ConnectionPacket::Receive(void** pbuffer, uint32* psize)
|
|||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
// There is only one listener thread per connection. No need to lock.
|
// There is only one listener thread per connection. No need to lock.
|
||||||
size = recv(fSock, buffer, size, 0);
|
size = recv(fSocket, buffer, size, 0);
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
result = errno;
|
result = errno;
|
||||||
free(buffer);
|
free(buffer);
|
||||||
@@ -304,31 +305,31 @@ ConnectionPacket::Receive(void** pbuffer, uint32* psize)
|
|||||||
return ECONNABORTED;
|
return ECONNABORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pbuffer = buffer;
|
*_buffer = buffer;
|
||||||
*psize = size;
|
*_size = size;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Connection::Connect(Connection **pconn, const ServerAddress& id)
|
Connection::Connect(Connection **_connection, const ServerAddress& address)
|
||||||
{
|
{
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
|
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sin_len = sizeof(struct sockaddr_in);
|
addr.sin_len = sizeof(struct sockaddr_in);
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = htonl(id.fAddress);
|
addr.sin_addr.s_addr = htonl(address.fAddress);
|
||||||
addr.sin_port = htons(id.fPort);
|
addr.sin_port = htons(address.fPort);
|
||||||
|
|
||||||
Connection* conn;
|
Connection* conn;
|
||||||
switch (id.fProtocol) {
|
switch (address.fProtocol) {
|
||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
conn = new(std::nothrow) ConnectionStream(addr, id.fProtocol);
|
conn = new(std::nothrow) ConnectionStream(addr, address.fProtocol);
|
||||||
break;
|
break;
|
||||||
case IPPROTO_UDP:
|
case IPPROTO_UDP:
|
||||||
conn = new(std::nothrow) ConnectionPacket(addr, id.fProtocol);
|
conn = new(std::nothrow) ConnectionPacket(addr, address.fProtocol);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
@@ -336,39 +337,39 @@ Connection::Connect(Connection **pconn, const ServerAddress& id)
|
|||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
status_t result = conn->_Connect();
|
status_t result = conn->Connect();
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
delete conn;
|
delete conn;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pconn = conn;
|
*_connection = conn;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Connection::_Connect()
|
Connection::Connect()
|
||||||
{
|
{
|
||||||
switch (fProtocol) {
|
switch (fProtocol) {
|
||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
fSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
fSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
break;
|
break;
|
||||||
case IPPROTO_UDP:
|
case IPPROTO_UDP:
|
||||||
fSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
fSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
if (fSock < 0)
|
if (fSocket < 0)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
status_t result = connect(fSock, (struct sockaddr*)&fServerAddress,
|
status_t result = connect(fSocket, (struct sockaddr*)&fServerAddress,
|
||||||
fServerAddress.sin_len);
|
fServerAddress.sin_len);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
result = errno;
|
result = errno;
|
||||||
close(fSock);
|
close(fSocket);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,9 +381,9 @@ status_t
|
|||||||
Connection::Reconnect()
|
Connection::Reconnect()
|
||||||
{
|
{
|
||||||
release_sem(fWaitCancel);
|
release_sem(fWaitCancel);
|
||||||
close(fSock);
|
close(fSocket);
|
||||||
acquire_sem(fWaitCancel);
|
acquire_sem(fWaitCancel);
|
||||||
return _Connect();
|
return Connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -391,8 +392,7 @@ Connection::Disconnect()
|
|||||||
{
|
{
|
||||||
release_sem(fWaitCancel);
|
release_sem(fWaitCancel);
|
||||||
|
|
||||||
int sock = fSock;
|
close(fSocket);
|
||||||
fSock = -1;
|
fSocket = -1;
|
||||||
close(sock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,36 +20,37 @@ struct ServerAddress {
|
|||||||
uint16 fPort;
|
uint16 fPort;
|
||||||
int fProtocol;
|
int fProtocol;
|
||||||
|
|
||||||
bool operator==(const ServerAddress& x);
|
bool operator==(const ServerAddress& address);
|
||||||
bool operator<(const ServerAddress& x);
|
bool operator<(const ServerAddress& address);
|
||||||
|
|
||||||
ServerAddress& operator=(const ServerAddress& x);
|
ServerAddress& operator=(const ServerAddress& address);
|
||||||
|
|
||||||
static status_t ResolveName(const char* name,
|
static status_t ResolveName(const char* name,
|
||||||
ServerAddress* addr);
|
ServerAddress* address);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Connection {
|
class Connection {
|
||||||
public:
|
public:
|
||||||
static status_t Connect(Connection **conn,
|
static status_t Connect(Connection **connection,
|
||||||
const ServerAddress& id);
|
const ServerAddress& address);
|
||||||
virtual ~Connection();
|
virtual ~Connection();
|
||||||
|
|
||||||
virtual status_t Send(const void* buffer, uint32 size) = 0;
|
virtual status_t Send(const void* buffer, uint32 size) = 0;
|
||||||
virtual status_t Receive(void** buffer, uint32* size) = 0;
|
virtual status_t Receive(void** buffer, uint32* size) = 0;
|
||||||
|
|
||||||
status_t GetLocalID(ServerAddress* addr);
|
status_t GetLocalAddress(ServerAddress* address);
|
||||||
|
|
||||||
status_t Reconnect();
|
status_t Reconnect();
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Connection(const sockaddr_in& addr, int proto);
|
Connection(const sockaddr_in& address,
|
||||||
status_t _Connect();
|
int protocol);
|
||||||
|
status_t Connect();
|
||||||
|
|
||||||
sem_id fWaitCancel;
|
sem_id fWaitCancel;
|
||||||
int fSock;
|
int fSocket;
|
||||||
mutex fSockLock;
|
mutex fSocketLock;
|
||||||
|
|
||||||
const int fProtocol;
|
const int fProtocol;
|
||||||
const sockaddr_in fServerAddress;
|
const sockaddr_in fServerAddress;
|
||||||
@@ -57,8 +58,8 @@ protected:
|
|||||||
|
|
||||||
class ConnectionStream : public Connection {
|
class ConnectionStream : public Connection {
|
||||||
public:
|
public:
|
||||||
ConnectionStream(const sockaddr_in& addr,
|
ConnectionStream(const sockaddr_in& address,
|
||||||
int proto);
|
int protocol);
|
||||||
|
|
||||||
virtual status_t Send(const void* buffer, uint32 size);
|
virtual status_t Send(const void* buffer, uint32 size);
|
||||||
virtual status_t Receive(void** buffer, uint32* size);
|
virtual status_t Receive(void** buffer, uint32* size);
|
||||||
@@ -66,8 +67,8 @@ public:
|
|||||||
|
|
||||||
class ConnectionPacket : public Connection {
|
class ConnectionPacket : public Connection {
|
||||||
public:
|
public:
|
||||||
ConnectionPacket(const sockaddr_in& addr,
|
ConnectionPacket(const sockaddr_in& address,
|
||||||
int proto);
|
int protocol);
|
||||||
|
|
||||||
virtual status_t Send(const void* buffer, uint32 size);
|
virtual status_t Send(const void* buffer, uint32 size);
|
||||||
virtual status_t Receive(void** buffer, uint32* size);
|
virtual status_t Receive(void** buffer, uint32* size);
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ RequestManager::~RequestManager()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RequestManager::AddRequest(Request* req)
|
RequestManager::AddRequest(Request* request)
|
||||||
{
|
{
|
||||||
MutexLocker _(fLock);
|
MutexLocker _(fLock);
|
||||||
if (fQueueTail != NULL)
|
if (fQueueTail != NULL)
|
||||||
fQueueTail->fNext = req;
|
fQueueTail->fNext = request;
|
||||||
else
|
else
|
||||||
fQueueHead = req;
|
fQueueHead = request;
|
||||||
fQueueTail = req;
|
fQueueTail = request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,10 +72,10 @@ RequestManager::FindRequest(uint32 xid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Server::Server(Connection* conn, ServerAddress* addr)
|
Server::Server(Connection* connection, ServerAddress* address)
|
||||||
:
|
:
|
||||||
fConnection(conn),
|
fConnection(connection),
|
||||||
fAddress(addr),
|
fAddress(address),
|
||||||
fPrivateData(NULL),
|
fPrivateData(NULL),
|
||||||
fXID(rand() << 1)
|
fXID(rand() << 1)
|
||||||
{
|
{
|
||||||
@@ -164,19 +164,19 @@ Server::SendCallAsync(Call* call, Reply** reply, Request** request)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Server::ResendCallAsync(Call* call, Request* req)
|
Server::ResendCallAsync(Call* call, Request* request)
|
||||||
{
|
{
|
||||||
if (fThreadError != B_OK) {
|
if (fThreadError != B_OK) {
|
||||||
fRequests.FindRequest(req->fXID);
|
fRequests.FindRequest(request->fXID);
|
||||||
delete req;
|
delete request;
|
||||||
return fThreadError;
|
return fThreadError;
|
||||||
}
|
}
|
||||||
|
|
||||||
XDR::WriteStream& stream = call->Stream();
|
XDR::WriteStream& stream = call->Stream();
|
||||||
status_t result = fConnection->Send(stream.Buffer(), stream.Size());
|
status_t result = fConnection->Send(stream.Buffer(), stream.Size());
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
fRequests.FindRequest(req->fXID);
|
fRequests.FindRequest(request->fXID);
|
||||||
delete req;
|
delete request;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,9 +257,9 @@ Server::_Listener()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Server::_ListenerThreadStart(void* ptr)
|
Server::_ListenerThreadStart(void* object)
|
||||||
{
|
{
|
||||||
Server* server = reinterpret_cast<Server*>(ptr);
|
Server* server = reinterpret_cast<Server*>(object);
|
||||||
return server->_Listener();
|
return server->_Listener();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,16 +279,16 @@ ServerManager::~ServerManager()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ServerManager::Acquire(Server** pserv, const ServerAddress& id,
|
ServerManager::Acquire(Server** _server, const ServerAddress& address,
|
||||||
ProgramData* (*createPriv)(Server*))
|
ProgramData* (*createPrivateData)(Server*))
|
||||||
{
|
{
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
MutexLocker locker(fLock);
|
MutexLocker locker(fLock);
|
||||||
ServerNode* node = _Find(id);
|
ServerNode* node = _Find(address);
|
||||||
if (node != NULL) {
|
if (node != NULL) {
|
||||||
node->fRefCount++;
|
node->fRefCount++;
|
||||||
*pserv = node->fServer;
|
*_server = node->fServer;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -297,10 +297,10 @@ ServerManager::Acquire(Server** pserv, const ServerAddress& id,
|
|||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
node->fID = id;
|
node->fID = address;
|
||||||
|
|
||||||
Connection* conn;
|
Connection* conn;
|
||||||
result = Connection::Connect(&conn, id);
|
result = Connection::Connect(&conn, address);
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
delete node;
|
delete node;
|
||||||
return result;
|
return result;
|
||||||
@@ -312,7 +312,7 @@ ServerManager::Acquire(Server** pserv, const ServerAddress& id,
|
|||||||
delete conn;
|
delete conn;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
node->fServer->SetPrivateData(createPriv(node->fServer));
|
node->fServer->SetPrivateData(createPrivateData(node->fServer));
|
||||||
|
|
||||||
node->fRefCount = 1;
|
node->fRefCount = 1;
|
||||||
node->fLeft = node->fRight = NULL;
|
node->fLeft = node->fRight = NULL;
|
||||||
@@ -323,20 +323,20 @@ ServerManager::Acquire(Server** pserv, const ServerAddress& id,
|
|||||||
|
|
||||||
delete node->fServer;
|
delete node->fServer;
|
||||||
delete node;
|
delete node;
|
||||||
*pserv = nd->fServer;
|
*_server = nd->fServer;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pserv = node->fServer;
|
*_server = node->fServer;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerManager::Release(Server* serv)
|
ServerManager::Release(Server* server)
|
||||||
{
|
{
|
||||||
MutexLocker _(fLock);
|
MutexLocker _(fLock);
|
||||||
ServerNode* node = _Find(serv->ID());
|
ServerNode* node = _Find(server->ID());
|
||||||
if (node != NULL) {
|
if (node != NULL) {
|
||||||
node->fRefCount--;
|
node->fRefCount--;
|
||||||
|
|
||||||
@@ -350,13 +350,13 @@ ServerManager::Release(Server* serv)
|
|||||||
|
|
||||||
|
|
||||||
ServerNode*
|
ServerNode*
|
||||||
ServerManager::_Find(const ServerAddress& id)
|
ServerManager::_Find(const ServerAddress& address)
|
||||||
{
|
{
|
||||||
ServerNode* node = fRoot;
|
ServerNode* node = fRoot;
|
||||||
while (node != NULL) {
|
while (node != NULL) {
|
||||||
if (node->fID == id)
|
if (node->fID == address)
|
||||||
return node;
|
return node;
|
||||||
if (node->fID < id)
|
if (node->fID < address)
|
||||||
node = node->fRight;
|
node = node->fRight;
|
||||||
else
|
else
|
||||||
node = node->fLeft;
|
node = node->fLeft;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public:
|
|||||||
RequestManager();
|
RequestManager();
|
||||||
~RequestManager();
|
~RequestManager();
|
||||||
|
|
||||||
void AddRequest(Request* req);
|
void AddRequest(Request* request);
|
||||||
Request* FindRequest(uint32 xid);
|
Request* FindRequest(uint32 xid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -52,15 +52,17 @@ public:
|
|||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
public:
|
public:
|
||||||
Server(Connection* conn,
|
Server(Connection* connection,
|
||||||
ServerAddress* addr);
|
ServerAddress* address);
|
||||||
virtual ~Server();
|
virtual ~Server();
|
||||||
|
|
||||||
status_t SendCall(Call* call, Reply** reply);
|
status_t SendCall(Call* call, Reply** reply);
|
||||||
|
|
||||||
status_t SendCallAsync(Call* call, Reply** reply,
|
status_t SendCallAsync(Call* call, Reply** reply,
|
||||||
Request** request);
|
Request** request);
|
||||||
status_t ResendCallAsync(Call* call, Request* req);
|
status_t ResendCallAsync(Call* call,
|
||||||
|
Request* request);
|
||||||
|
|
||||||
inline status_t WaitCall(Request* request,
|
inline status_t WaitCall(Request* request,
|
||||||
bigtime_t time = kWaitTime);
|
bigtime_t time = kWaitTime);
|
||||||
inline status_t CancelCall(Request* request);
|
inline status_t CancelCall(Request* request);
|
||||||
@@ -72,7 +74,7 @@ public:
|
|||||||
inline ServerAddress LocalID() const;
|
inline ServerAddress LocalID() const;
|
||||||
|
|
||||||
inline ProgramData* PrivateData();
|
inline ProgramData* PrivateData();
|
||||||
inline void SetPrivateData(ProgramData* priv);
|
inline void SetPrivateData(ProgramData* privateData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline uint32 _GetXID();
|
inline uint32 _GetXID();
|
||||||
@@ -80,7 +82,7 @@ private:
|
|||||||
status_t _StartListening();
|
status_t _StartListening();
|
||||||
|
|
||||||
status_t _Listener();
|
status_t _Listener();
|
||||||
static status_t _ListenerThreadStart(void* ptr);
|
static status_t _ListenerThreadStart(void* object);
|
||||||
|
|
||||||
thread_id fThread;
|
thread_id fThread;
|
||||||
bool fThreadCancel;
|
bool fThreadCancel;
|
||||||
@@ -126,7 +128,7 @@ Server::LocalID() const
|
|||||||
{
|
{
|
||||||
ServerAddress addr;
|
ServerAddress addr;
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
fConnection->GetLocalID(&addr);
|
fConnection->GetLocalAddress(&addr);
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,10 +141,10 @@ Server::PrivateData()
|
|||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
Server::SetPrivateData(ProgramData* priv)
|
Server::SetPrivateData(ProgramData* privateData)
|
||||||
{
|
{
|
||||||
delete fPrivateData;
|
delete fPrivateData;
|
||||||
fPrivateData = priv;
|
fPrivateData = privateData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -160,13 +162,13 @@ public:
|
|||||||
ServerManager();
|
ServerManager();
|
||||||
~ServerManager();
|
~ServerManager();
|
||||||
|
|
||||||
status_t Acquire(Server** pserv, const ServerAddress& id,
|
status_t Acquire(Server** _server, const ServerAddress& address,
|
||||||
ProgramData* (*createPriv)(Server*));
|
ProgramData* (*createPrivateData)(Server*));
|
||||||
void Release(Server* serv);
|
void Release(Server* server);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ServerNode* _Find(const ServerAddress& id);
|
ServerNode* _Find(const ServerAddress& address);
|
||||||
void _Delete(ServerNode* node);
|
void _Delete(ServerNode* node);
|
||||||
ServerNode* _Insert(ServerNode* node);
|
ServerNode* _Insert(ServerNode* node);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user