nfs4: k- variants of socket functions are not really needed

This commit is contained in:
Pawel Dziepak
2012-06-29 02:14:35 +02:00
parent 60a8140ded
commit a01e1e9961
3 changed files with 13 additions and 41 deletions
@@ -14,7 +14,6 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <drivers/ksocket.h>
#include <util/kernel_cpp.h> #include <util/kernel_cpp.h>
@@ -22,9 +21,6 @@
#define MAX_PACKET_SIZE 65535 #define MAX_PACKET_SIZE 65535
KSOCKET_MODULE_DECL;
bool bool
ServerAddress::operator==(const ServerAddress& x) ServerAddress::operator==(const ServerAddress& x)
{ {
@@ -66,7 +62,7 @@ Connection::Connection(const sockaddr_in& addr, Transport proto, bool markers)
Connection::~Connection() Connection::~Connection()
{ {
if (fSock != -1) if (fSock != -1)
kclosesocket(fSock); close(fSock);
mutex_destroy(&fSockLock); mutex_destroy(&fSockLock);
} }
@@ -76,7 +72,7 @@ Connection::GetLocalID(ServerAddress* addr)
{ {
struct sockaddr_in saddr; struct sockaddr_in saddr;
socklen_t slen = sizeof(addr); socklen_t slen = sizeof(addr);
status_t result = kgetsockname(fSock, (struct sockaddr*)&saddr, &slen); status_t result = getsockname(fSock, (struct sockaddr*)&saddr, &slen);
if (result != B_OK) if (result != B_OK)
return result; return result;
@@ -105,7 +101,7 @@ Connection::_SendStream(const void* buffer, uint32 size)
uint32 sent = 0; uint32 sent = 0;
mutex_lock(&fSockLock); mutex_lock(&fSockLock);
do { do {
result = ksend(fSock, buf + sent, size + sizeof(uint32) - sent, 0); result = send(fSock, 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(&fSockLock);
@@ -127,7 +123,7 @@ status_t
Connection::_SendPacket(const void* buffer, uint32 size) Connection::_SendPacket(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 = ksend(fSock, buffer, size, 0); status_t result = send(fSock, buffer, size, 0);
if (result < 0) if (result < 0)
return errno; return errno;
@@ -149,7 +145,7 @@ Connection::_ReceiveStream(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 = krecv(fSock, &record_size + received, result = recv(fSock, &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));
@@ -175,7 +171,7 @@ Connection::_ReceiveStream(void** pbuffer, uint32* psize)
received = 0; received = 0;
do { do {
result = krecv(fSock, (uint8*)buffer + size + received, result = recv(fSock, (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));
@@ -207,7 +203,7 @@ Connection::_ReceivePacket(void** pbuffer, uint32* psize)
return B_NO_MEMORY; return B_NO_MEMORY;
// 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 = krecv(fSock, buffer, size, 0); size = recv(fSock, buffer, size, 0);
if (size < 0) { if (size < 0) {
result = errno; result = errno;
free(buffer); free(buffer);
@@ -257,10 +253,10 @@ Connection::_Connect()
{ {
switch (fProtocol) { switch (fProtocol) {
case ProtocolTCP: case ProtocolTCP:
fSock = ksocket(AF_INET, SOCK_STREAM, IPPROTO_TCP); fSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
break; break;
case ProtocolUDP: case ProtocolUDP:
fSock = ksocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); fSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
break; break;
default: default:
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -268,11 +264,11 @@ Connection::_Connect()
if (fSock < 0) if (fSock < 0)
return errno; return errno;
status_t result = kconnect(fSock, (struct sockaddr*)&fServerAddress, status_t result = connect(fSock, (struct sockaddr*)&fServerAddress,
fServerAddress.sin_len); fServerAddress.sin_len);
if (result < 0) { if (result < 0) {
result = errno; result = errno;
kclosesocket(fSock); close(fSock);
return result; return result;
} }
@@ -283,7 +279,7 @@ Connection::_Connect()
status_t status_t
Connection::Reconnect() Connection::Reconnect()
{ {
kclosesocket(fSock); close(fSock);
return _Connect(); return _Connect();
} }
@@ -293,20 +289,6 @@ Connection::Disconnect()
{ {
int sock = fSock; int sock = fSock;
fSock = -1; fSock = -1;
kclosesocket(sock); close(sock);
}
status_t
Connection::Init()
{
return ksocket_init();
}
status_t
Connection::CleanUp()
{
return ksocket_cleanup();
} }
@@ -45,9 +45,6 @@ public:
status_t Reconnect(); status_t Reconnect();
void Disconnect(); void Disconnect();
static status_t Init();
static status_t CleanUp();
private: private:
Connection(const sockaddr_in& addr, Connection(const sockaddr_in& addr,
Transport proto, bool markers); Transport proto, bool markers);
@@ -243,10 +243,6 @@ nfs4_init()
{ {
dprintf("NFS4 Init\n"); dprintf("NFS4 Init\n");
status_t result = Connection::Init();
if (result != B_OK)
return result;
gRPCServerManager = new(std::nothrow) RPC::ServerManager; gRPCServerManager = new(std::nothrow) RPC::ServerManager;
if (gRPCServerManager == NULL) if (gRPCServerManager == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -261,9 +257,6 @@ nfs4_uninit()
delete gRPCServerManager; delete gRPCServerManager;
status_t result = Connection::CleanUp();
if (result != B_OK)
return result;
return B_OK; return B_OK;
} }