- Merge aicom-network-branch (still without the NDIS stuff)
[reactos.git] / reactos / lib / drivers / oskittcp / oskittcp / sleep.c
1 #include <oskittcp.h>
2 #include <sys/callout.h>
3 #include <oskitfreebsd.h>
4 #include <oskitdebug.h>
5
6 /* clock_init */
7 int ncallout = 256;
8 struct callout *callout;
9
10 void init_freebsd_sched() {
11 }
12
13 int tsleep( void *token, int priority, char *wmesg, int tmio ) {
14 if( !OtcpEvent.Sleep ) panic("no sleep");
15 return
16 OtcpEvent.Sleep( OtcpEvent.ClientData, token, priority, wmesg, tmio );
17 }
18
19 void wakeup( struct socket *so, void *token ) {
20 OSK_UINT flags = 0;
21
22 OS_DbgPrint
23 (OSK_MID_TRACE,("XXX Bytes to receive: %d state %x\n",
24 so->so_rcv.sb_cc, so->so_state));
25
26 if( so->so_state & SS_ISCONNECTED ) {
27 OS_DbgPrint(OSK_MID_TRACE,("Socket connected!\n"));
28 flags |= SEL_CONNECT;
29 }
30 if( so->so_q ) {
31 OS_DbgPrint(OSK_MID_TRACE,("Socket accepting q\n"));
32 flags |= SEL_ACCEPT;
33 }
34 if( so->so_rcv.sb_cc > 0 ) {
35 OS_DbgPrint(OSK_MID_TRACE,("Socket readable\n"));
36 flags |= SEL_READ;
37 }
38 if( 0 < sbspace(&so->so_snd) ) {
39 OS_DbgPrint(OSK_MID_TRACE,("Socket writeable\n"));
40 flags |= SEL_WRITE;
41 }
42 if (!so->so_pcb) {
43 OS_DbgPrint(OSK_MID_TRACE,("Socket dying\n"));
44 flags |= SEL_FIN;
45 }
46
47 OS_DbgPrint(OSK_MID_TRACE,("Wakeup %x (socket %x, state %x)!\n",
48 token, so,
49 so->so_state));
50
51 if( OtcpEvent.SocketState )
52 OtcpEvent.SocketState( OtcpEvent.ClientData,
53 so,
54 so ? so->so_connection : 0,
55 flags );
56
57 if( OtcpEvent.Wakeup )
58 OtcpEvent.Wakeup( OtcpEvent.ClientData, token );
59
60 OS_DbgPrint(OSK_MID_TRACE,("Wakeup done %x\n", token));
61 }
62
63 /* ---------------------------------------------------------------------- */
64
65
66 static void
67 timeout_init(void)
68 {
69 int i;
70
71 callout = (struct callout *)
72 malloc(sizeof(struct callout) * ncallout, M_FREE, M_WAITOK);
73 if (!callout)
74 panic("can't allocate callout queue!\n");
75
76 /*
77 * Initialize callouts
78 */
79 callfree = callout;
80 for (i = 1; i < ncallout; i++)
81 callout[i-1].c_next = &callout[i];
82
83 }
84
85 /* get clock up and running */
86 void clock_init()
87 {
88 timeout_init();
89 /* inittodr(0); // what does this do? */
90 /* boottime = kern_time; */
91 /* Start a clock we can use for timeouts */
92 }
93