2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef UNIX_ENDPOINT_H
6 #define UNIX_ENDPOINT_H
10 #include <Referenceable.h>
13 #include <util/DoublyLinkedList.h>
14 #include <util/OpenHashTable.h>
17 #include <net_protocol.h>
18 #include <net_socket.h>
19 #include <ProtocolUtilities.h>
22 #include "UnixAddress.h"
29 enum unix_endpoint_state
{
30 UNIX_ENDPOINT_NOT_CONNECTED
,
31 UNIX_ENDPOINT_LISTENING
,
32 UNIX_ENDPOINT_CONNECTED
,
37 typedef AutoLocker
<UnixEndpoint
> UnixEndpointLocker
;
40 class UnixEndpoint
: public net_protocol
, public ProtocolSocket
,
41 public BReferenceable
{
43 UnixEndpoint(net_socket
* socket
);
44 virtual ~UnixEndpoint();
55 return mutex_lock(&fLock
) == B_OK
;
63 status_t
Bind(const struct sockaddr
*_address
);
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
);
78 status_t
SetReceiveBufferSize(size_t size
);
79 status_t
GetPeerCredentials(ucred
* credentials
);
81 status_t
Shutdown(int direction
);
85 return !fIsChild
&& fAddress
.IsValid();
88 const UnixAddress
& Address() const
93 UnixEndpoint
*& HashTableLink()
95 return fAddressHashLink
;
99 void _Spawn(UnixEndpoint
* connectingEndpoint
,
100 UnixEndpoint
* listeningEndpoint
, UnixFifo
* fifo
);
102 status_t
_LockConnectedEndpoints(UnixEndpointLocker
& locker
,
103 UnixEndpointLocker
& peerLocker
);
105 status_t
_Bind(struct vnode
* vnode
);
106 status_t
_Bind(int32 internalID
);
109 void _UnsetReceiveFifo();
110 void _StopListening();
114 UnixAddress fAddress
;
115 UnixEndpoint
* fAddressHashLink
;
116 UnixEndpoint
* fPeerEndpoint
;
117 UnixFifo
* fReceiveFifo
;
118 unix_endpoint_state fState
;
119 sem_id fAcceptSemaphore
;
124 #endif // UNIX_ENDPOINT_H