2016-05-01 01:29:55 +03:00
|
|
|
/*
|
|
|
|
* 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);
|
2016-05-15 04:22:26 +03:00
|
|
|
virtual status_t SendReply(const BMessage& message,
|
|
|
|
const BMessage& reply);
|
2016-05-01 01:29:55 +03:00
|
|
|
|
|
|
|
// wait for unsolicited message on socket
|
|
|
|
virtual status_t ReceiveMessage(BMessage& _message,
|
|
|
|
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
|
|
|
|
|
|
|
private:
|
2016-05-15 04:22:26 +03:00
|
|
|
struct Private;
|
|
|
|
private:
|
|
|
|
BSocketMessenger(const BSocketMessenger&);
|
|
|
|
BSocketMessenger& operator=(const BSocketMessenger&);
|
|
|
|
|
|
|
|
void _Init();
|
|
|
|
status_t _WaitForMessage(bigtime_t timeout);
|
2016-05-01 01:29:55 +03:00
|
|
|
status_t _SendMessage(const BMessage& message);
|
2016-05-15 04:22:26 +03:00
|
|
|
status_t _ReadMessage(BMessage& _message);
|
|
|
|
status_t _ReadReply(int64 replyID,
|
|
|
|
BMessage& _reply, bigtime_t timeout);
|
|
|
|
|
|
|
|
static status_t _MessageReader(void* arg);
|
2016-05-01 01:29:55 +03:00
|
|
|
|
|
|
|
private:
|
2016-05-15 04:22:26 +03:00
|
|
|
Private* fPrivateData;
|
2016-05-01 01:29:55 +03:00
|
|
|
BSocket fSocket;
|
|
|
|
status_t fInitStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SOCKET_MESSENGER_H
|