mirror of
https://review.haiku-os.org/haiku
synced 2025-02-08 22:58:18 +01:00
- Introduces new network API class BSocketMessenger, allowing one to send and receive BMessages across a network socket in a BMessenger-like fashion. Still very much WIP, hence currently not exposed via public headers. Based partly on previous work by Axel.
57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
/*
|
|
* Copyright 2011-2016, Haiku, Inc. All Rights Reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef SOCKET_MESSENGER_H
|
|
#define SOCKET_MESSENGER_H
|
|
|
|
#include <Socket.h>
|
|
|
|
class BMessage;
|
|
class BMessenger;
|
|
|
|
|
|
class BSocketMessenger {
|
|
public:
|
|
BSocketMessenger();
|
|
BSocketMessenger(
|
|
const BNetworkAddress& address,
|
|
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
// adopt an existing already connected socket.
|
|
BSocketMessenger(const BSocket& socket);
|
|
virtual ~BSocketMessenger();
|
|
|
|
void Unset();
|
|
status_t SetTo(const BNetworkAddress& address,
|
|
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
status_t SetTo(const BSocketMessenger& target,
|
|
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
|
|
status_t InitCheck() const { return fInitStatus; }
|
|
|
|
const BNetworkAddress& Address() const { return fSocket.Peer(); }
|
|
|
|
virtual status_t SendMessage(const BMessage& message);
|
|
virtual status_t SendMessage(const BMessage& message,
|
|
BMessage& _reply,
|
|
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
virtual status_t SendMessage(const BMessage& message,
|
|
BMessenger& replyTarget,
|
|
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
|
|
// wait for unsolicited message on socket
|
|
virtual status_t ReceiveMessage(BMessage& _message,
|
|
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
|
|
private:
|
|
status_t _SendMessage(const BMessage& message);
|
|
status_t _ReadMessage(BMessage& _message,
|
|
bigtime_t timeout);
|
|
|
|
private:
|
|
BSocket fSocket;
|
|
status_t fInitStatus;
|
|
};
|
|
|
|
#endif // SOCKET_MESSENGER_H
|