btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / add-ons / kernel / network / protocols / l2cap / L2capEndpoint.h
blobddc30243d1d043846a8aecc49f9eb1a0b01beb74
1 /*
2 * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5 #ifndef L2CAP_ENDPOINT_H
6 #define L2CAP_ENDPOINT_H
8 #include <sys/stat.h>
10 #include <lock.h>
11 #include <util/DoublyLinkedList.h>
12 #include <util/OpenHashTable.h>
14 #include <net_protocol.h>
15 #include <net_socket.h>
16 #include <ProtocolUtilities.h>
18 #include "l2cap_internal.h"
20 extern net_stack_module_info* gStackModule;
22 class L2capEndpoint : public net_protocol,
23 public ProtocolSocket,
24 public DoublyLinkedListLinkImpl<L2capEndpoint> {
26 public:
27 L2capEndpoint(net_socket* socket);
28 virtual ~L2capEndpoint();
30 status_t Init();
31 void Uninit();
33 status_t Open();
34 status_t Close();
35 status_t Free();
37 bool Lock()
39 return mutex_lock(&fLock) == B_OK;
42 void Unlock()
44 mutex_unlock(&fLock);
47 status_t Bind(const struct sockaddr* _address);
48 status_t Unbind();
49 status_t Listen(int backlog);
50 status_t Connect(const struct sockaddr* address);
51 status_t Accept(net_socket** _acceptedSocket);
53 ssize_t Send(const iovec* vecs, size_t vecCount,
54 ancillary_data_container* ancillaryData);
55 ssize_t Receive(const iovec* vecs, size_t vecCount,
56 ancillary_data_container** _ancillaryData,
57 struct sockaddr* _address, socklen_t* _addressLength);
59 ssize_t ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer);
60 ssize_t SendData(net_buffer* buffer);
61 ssize_t Sendable();
62 ssize_t Receivable();
64 status_t SetReceiveBufferSize(size_t size);
65 status_t GetPeerCredentials(ucred* credentials);
67 status_t Shutdown(int direction);
69 void BindNewEnpointToChannel(L2capChannel* channel);
70 void BindToChannel(L2capChannel* channel);
71 status_t MarkEstablished();
72 status_t MarkClosed();
74 static L2capEndpoint* ForPsm(uint16 psm);
76 bool RequiresConfiguration()
78 return fConfigurationSet;
81 ChannelConfiguration fConfiguration;
82 bool fConfigurationSet;
83 net_fifo fReceivingFifo;
85 private:
86 typedef enum {
87 // establishing a connection
88 CLOSED,
89 BOUND,
90 LISTEN,
91 CONNECTING,
92 ESTABLISHED,
94 // peer closes the connection
95 FINISH_RECEIVED,
96 WAIT_FOR_FINISH_ACKNOWLEDGE,
98 // we close the connection
99 FINISH_SENT,
100 FINISH_ACKNOWLEDGED,
101 CLOSING,
102 TIME_WAIT
103 } State;
105 mutex fLock;
106 State fState;
107 sem_id fEstablishSemaphore;
108 L2capEndpoint* fPeerEndpoint;
109 L2capChannel* fChannel;
114 extern DoublyLinkedList<L2capEndpoint> EndpointList;
116 #endif // L2CAP_ENDPOINT_H