Watt-32 tcp/ip  2.2 dev-rel.10
sock_sel.c
Go to the documentation of this file.
1 
4 #include <stdio.h>
5 
6 #include "copyrigh.h"
7 #include "wattcp.h"
8 #include "pcbuf.h"
9 #include "pctcp.h"
10 
11 /*
12  * sock_sselect - returns one of several constants indicating
13  * SOCKESTABLISHED - tcp connection has been established
14  * SOCKDATAREAY - tcp/udp data ready for reading
15  * SOCKCLOSED - socket has been closed
16  */
17 int W32_CALL sock_sselect (const sock_type *s, int waitstate)
18 {
19  /* are we connected ?
20  */
21  if (waitstate == SOCKDATAREADY && s->tcp.rx_datalen > 0)
22  return (SOCKDATAREADY);
23 
24  if (s->tcp.ip_type == 0)
25  return (SOCKCLOSED);
26 
27  if (waitstate == SOCKESTABLISHED)
28  {
29  if (s->tcp.ip_type == UDP_PROTO ||
30  s->tcp.state == tcp_StateESTAB ||
31  s->tcp.state == tcp_StateESTCL ||
32  s->tcp.state == tcp_StateCLOSWT)
33  return (SOCKESTABLISHED);
34  }
35  return (0);
36 }
37 
38 /*
39  * Returns 'simplified' enum telling what state the tcp socket is currently
40  * in, GvB 2002-09
41  */
42 enum TCP_SIMPLE_STATE W32_CALL tcp_simple_state (const _tcp_Socket *s)
43 {
44  if (s->ip_type != TCP_PROTO ||
45  s->state == tcp_StateCLOSED)
46  return (TCP_CLOSED);
47 
48  if (s->state == tcp_StateLISTEN)
49  return (TCP_LISTENING);
50 
51  if (s->state < tcp_StateESTAB)
52  return (TCP_OPENING);
53 
54  if (s->state == tcp_StateESTAB)
55  return (TCP_OPEN);
56 
57  return (TCP_CLOSING);
58 }
59 
Core definitions.
UINT state
tcp connection state
Definition: wattcp.h:622