btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / add-ons / kernel / network / protocols / unix / UnixEndpoint.h
blob5e09fb022f8a13b2db4cb101f65a642e090d1685
1 /*
2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef UNIX_ENDPOINT_H
6 #define UNIX_ENDPOINT_H
8 #include <sys/stat.h>
10 #include <Referenceable.h>
12 #include <lock.h>
13 #include <util/DoublyLinkedList.h>
14 #include <util/OpenHashTable.h>
15 #include <vfs.h>
17 #include <net_protocol.h>
18 #include <net_socket.h>
19 #include <ProtocolUtilities.h>
21 #include "unix.h"
22 #include "UnixAddress.h"
25 class UnixEndpoint;
26 class UnixFifo;
29 enum unix_endpoint_state {
30 UNIX_ENDPOINT_NOT_CONNECTED,
31 UNIX_ENDPOINT_LISTENING,
32 UNIX_ENDPOINT_CONNECTED,
33 UNIX_ENDPOINT_CLOSED
37 typedef AutoLocker<UnixEndpoint> UnixEndpointLocker;
40 class UnixEndpoint : public net_protocol, public ProtocolSocket,
41 public BReferenceable {
42 public:
43 UnixEndpoint(net_socket* socket);
44 virtual ~UnixEndpoint();
46 status_t Init();
47 void Uninit();
49 status_t Open();
50 status_t Close();
51 status_t Free();
53 bool Lock()
55 return mutex_lock(&fLock) == B_OK;
58 void Unlock()
60 mutex_unlock(&fLock);
63 status_t Bind(const struct sockaddr *_address);
64 status_t Unbind();
65 status_t Listen(int backlog);
66 status_t Connect(const struct sockaddr *address);
67 status_t Accept(net_socket **_acceptedSocket);
69 ssize_t Send(const iovec *vecs, size_t vecCount,
70 ancillary_data_container *ancillaryData);
71 ssize_t Receive(const iovec *vecs, size_t vecCount,
72 ancillary_data_container **_ancillaryData, struct sockaddr *_address,
73 socklen_t *_addressLength);
75 ssize_t Sendable();
76 ssize_t Receivable();
78 status_t SetReceiveBufferSize(size_t size);
79 status_t GetPeerCredentials(ucred* credentials);
81 status_t Shutdown(int direction);
83 bool IsBound() const
85 return !fIsChild && fAddress.IsValid();
88 const UnixAddress& Address() const
90 return fAddress;
93 UnixEndpoint*& HashTableLink()
95 return fAddressHashLink;
98 private:
99 void _Spawn(UnixEndpoint* connectingEndpoint,
100 UnixEndpoint* listeningEndpoint, UnixFifo* fifo);
101 void _Disconnect();
102 status_t _LockConnectedEndpoints(UnixEndpointLocker& locker,
103 UnixEndpointLocker& peerLocker);
105 status_t _Bind(struct vnode* vnode);
106 status_t _Bind(int32 internalID);
107 status_t _Unbind();
109 void _UnsetReceiveFifo();
110 void _StopListening();
112 private:
113 mutex fLock;
114 UnixAddress fAddress;
115 UnixEndpoint* fAddressHashLink;
116 UnixEndpoint* fPeerEndpoint;
117 UnixFifo* fReceiveFifo;
118 unix_endpoint_state fState;
119 sem_id fAcceptSemaphore;
120 ucred fCredentials;
121 bool fIsChild;
124 #endif // UNIX_ENDPOINT_H