forked from vsamtuc/tinyos3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel_socket.h
90 lines (57 loc) · 1.86 KB
/
kernel_socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef __KERNEL_SOCKET_H
#define __KERNEL_SOCKET_H
#include "tinyos.h"
#include "kernel_dev.h"
#include "kernel_cc.h"
#include "kernel_streams.h"
#include "kernel_pipe.h"
typedef enum {
UNBOUND, /**< @brief SOCKET initialising */
PEER, /**< @brief ready to read n write */
LISTENER, /**< @brief listener socket */
} Socket_type;
typedef struct listener_socket_control_block
{
rlnode request_queue; /**< @brief Reference counter. */
CondVar has_request; // The condition variable that wakes if the listener has a request
} LSCB;
typedef struct unbound_socket_control_block
{
int stupid_variable;//A stupid variable that does nothing
} USCB;
typedef struct peer_socket_control_block
{
SCB* peer_socket;//Pointer to the other peer socket
PIPE_CB* read_pipe;
PIPE_CB* write_pipe;
} PSCB;
typedef struct socket_control_block
{
port_t port;//The port of the socket
Socket_type type;//The type of the socket which is enum (UNBOUND,PEER,LISTENER)
uint refcount;
FCB* fcb;//Pointer to the fcb to take the stream object and function
union {
PSCB* pscb;
LSCB* lscb;
USCB* uscb;
};
} SCB;
typedef struct request_node_struct
{
rlnode request_node;//The head node of the listeners list
uint admitted;//boolean Variable to check if the socket is admitted
CondVar wakeup_request;//The condition variable
SCB* scb;//Pointer to the Listening scb
}RNS;
Fid_t sys_Socket(port_t port);
int sys_Listen(Fid_t sock);
Fid_t sys_Accept(Fid_t lsock);
int sys_Connect(Fid_t sock, port_t port, timeout_t timeout);
int sys_Socket_Read(void* stream_object, char *buf, unsigned int size);
int sys_Socket_Write(void* stream_object, char *buf, unsigned int size);
int sys_Socket_Close(void* streamobj);
void SCB_decref(SCB* scb);
int sys_Socket_Void(void* stream_object, char *buf, unsigned int size);
PIPE_CB* construct_Pipe();
#endif