btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / net / SocketMessenger.h
blob42674a7c9386fdcbb5b2efa59ba2198d59b4a7a0
1 /*
2 * Copyright 2011-2016, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef SOCKET_MESSENGER_H
6 #define SOCKET_MESSENGER_H
8 #include <Socket.h>
10 class BMessage;
11 class BMessenger;
14 class BSocketMessenger {
15 public:
16 BSocketMessenger();
17 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();
24 void Unset();
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,
36 BMessage& _reply,
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);
48 private:
49 struct Private;
50 private:
51 BSocketMessenger(const BSocketMessenger&);
52 BSocketMessenger& operator=(const BSocketMessenger&);
54 void _Init();
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);
63 private:
64 Private* fPrivateData;
65 BSocket fSocket;
66 status_t fInitStatus;
69 #endif // SOCKET_MESSENGER_H