libbnetapi: Extend socket classes.

B{Abstract,Datagram,Secure}Socket:
- Add functionality to listen for and accept new connections, thus allowing
  one to use the socket classes for server functionality as well.

BSecureSocket:
- Adjust to take into account differences between how SSL needs to be called
  when accepting an incoming connection vs initiating an outbound one.
  The handshake on the accepted connection stills fails for unknown reasons
  at the moment though.

Note that these changes break the ABI, and thus any packages making use of
them directly will need a rebuild.
This commit is contained in:
Rene Gollent
2016-04-28 22:30:40 -04:00
parent 9503c26b5d
commit c9dd7d0ddf
9 changed files with 198 additions and 23 deletions
+11 -3
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2011, Haiku, Inc. All Rights Reserved.
* Copyright 2011-2016, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ABSTRACT_SOCKET_H
@@ -20,8 +20,12 @@ public:
status_t InitCheck() const;
virtual status_t Bind(const BNetworkAddress& local) = 0;
virtual status_t Bind(const BNetworkAddress& local, bool reuseAddr) = 0;
virtual bool IsBound() const;
virtual bool IsListening() const;
virtual status_t Listen(int backlog = 10);
virtual status_t Accept(BAbstractSocket*& _socket) = 0;
virtual status_t Connect(const BNetworkAddress& peer,
bigtime_t timeout = B_INFINITE_TIMEOUT) = 0;
@@ -44,9 +48,12 @@ public:
int Socket() const;
protected:
status_t Bind(const BNetworkAddress& local, int type);
status_t Bind(const BNetworkAddress& local,
bool reuseAddr, int type);
status_t Connect(const BNetworkAddress& peer, int type,
bigtime_t timeout = B_INFINITE_TIMEOUT);
status_t AcceptNext(int& _acceptedSocket,
BNetworkAddress& _peer);
private:
status_t _OpenIfNeeded(int family, int type);
@@ -60,6 +67,7 @@ protected:
BNetworkAddress fPeer;
bool fIsBound;
bool fIsConnected;
bool fIsListening;
};
+4 -1
View File
@@ -17,10 +17,13 @@ public:
BDatagramSocket(const BDatagramSocket& other);
virtual ~BDatagramSocket();
virtual status_t Bind(const BNetworkAddress& peer);
virtual status_t Bind(const BNetworkAddress& peer,
bool reuseAddr = true);
virtual status_t Connect(const BNetworkAddress& peer,
bigtime_t timeout = B_INFINITE_TIMEOUT);
virtual status_t Accept(BAbstractSocket*& _socket);
status_t SetBroadcast(bool broadcast);
void SetPeer(const BNetworkAddress& peer);
+6 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
* Copyright 2011-2016, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SECURE_SOCKET_H
@@ -27,6 +27,8 @@ public:
// BSocket implementation
virtual status_t Accept(BAbstractSocket*& _socket);
virtual status_t Connect(const BNetworkAddress& peer,
bigtime_t timeout = B_INFINITE_TIMEOUT);
virtual void Disconnect();
@@ -40,7 +42,9 @@ public:
virtual ssize_t Write(const void* buffer, size_t size);
protected:
status_t _Setup();
status_t _SetupCommon();
status_t _SetupConnect();
status_t _SetupAccept();
private:
friend class BCertificate;
+7 -4
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2011, Haiku, Inc. All Rights Reserved.
* Copyright 2011-2016, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SOCKET_H
@@ -17,7 +17,11 @@ public:
BSocket(const BSocket& other);
virtual ~BSocket();
virtual status_t Bind(const BNetworkAddress& peer);
virtual status_t Bind(const BNetworkAddress& peer,
bool reuseAddr = true);
virtual status_t Accept(BAbstractSocket*& _socket);
virtual status_t Connect(const BNetworkAddress& peer,
bigtime_t timeout = B_INFINITE_TIMEOUT);
@@ -26,8 +30,7 @@ public:
virtual ssize_t Read(void* buffer, size_t size);
virtual ssize_t Write(const void* buffer, size_t size);
private:
friend class BServerSocket;
protected:
void _SetTo(int fd, const BNetworkAddress& local,
const BNetworkAddress& peer);