2 * Copyright 2011-2016, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef SOCKET_MESSENGER_H
6 #define SOCKET_MESSENGER_H
14 class BSocketMessenger
{
18 const BNetworkAddress
& address
,
19 bigtime_t timeout
= B_INFINITE_TIMEOUT
);
20 // adopt an existing already connected socket.
21 BSocketMessenger(const BSocket
& socket
);
22 virtual ~BSocketMessenger();
25 status_t
SetTo(const BNetworkAddress
& address
,
26 bigtime_t timeout
= B_INFINITE_TIMEOUT
);
27 status_t
SetTo(const BSocketMessenger
& target
,
28 bigtime_t timeout
= B_INFINITE_TIMEOUT
);
30 status_t
InitCheck() const { return fInitStatus
; }
32 const BNetworkAddress
& Address() const { return fSocket
.Peer(); }
34 virtual status_t
SendMessage(const BMessage
& message
);
35 virtual status_t
SendMessage(const BMessage
& message
,
37 bigtime_t timeout
= B_INFINITE_TIMEOUT
);
38 virtual status_t
SendMessage(const BMessage
& message
,
39 BMessenger
& replyTarget
,
40 bigtime_t timeout
= B_INFINITE_TIMEOUT
);
41 virtual status_t
SendReply(const BMessage
& message
,
42 const BMessage
& reply
);
44 // wait for unsolicited message on socket
45 virtual status_t
ReceiveMessage(BMessage
& _message
,
46 bigtime_t timeout
= B_INFINITE_TIMEOUT
);
51 BSocketMessenger(const BSocketMessenger
&);
52 BSocketMessenger
& operator=(const BSocketMessenger
&);
55 status_t
_WaitForMessage(bigtime_t timeout
);
56 status_t
_SendMessage(const BMessage
& message
);
57 status_t
_ReadMessage(BMessage
& _message
);
58 status_t
_ReadReply(int64 replyID
,
59 BMessage
& _reply
, bigtime_t timeout
);
61 static status_t
_MessageReader(void* arg
);
64 Private
* fPrivateData
;
69 #endif // SOCKET_MESSENGER_H