70
70
#define MODES_DEBUG_BADCRC 3
71
71
#define MODES_DEBUG_GOODCRC 4
72
72
#define MODES_DEBUG_NOPREAMBLE 5
73
+ #define MODES_DEBUG_NET 6
73
74
74
75
/* When debug is set to MODES_DEBUG_NOPREAMBLE, the first sample must be
75
76
* at least greater than a given level for us to dump the signal. */
84
85
#define MODES_NET_INPUT_RAW_PORT 30001
85
86
#define MODES_NET_HTTP_PORT 8080
86
87
#define MODES_CLIENT_BUF_SIZE 1024
88
+ #define MODES_NET_SNDBUF_SIZE (1024*64)
87
89
88
90
#define MODES_NOTUSED (V ) ((void) V)
89
91
@@ -1734,9 +1736,13 @@ void modesAcceptClients(void) {
1734
1736
c -> fd = fd ;
1735
1737
c -> buflen = 0 ;
1736
1738
Modes .clients [fd ] = c ;
1739
+ anetSetSendBuffer (Modes .aneterr ,fd ,MODES_NET_SNDBUF_SIZE );
1737
1740
1738
1741
if (Modes .maxfd < fd ) Modes .maxfd = fd ;
1739
1742
j -- ; /* Try again with the same listening port. */
1743
+
1744
+ if (Modes .debug == MODES_DEBUG_NET )
1745
+ printf ("Created new client %d\n" , fd );
1740
1746
}
1741
1747
}
1742
1748
@@ -1746,6 +1752,9 @@ void modesFreeClient(int fd) {
1746
1752
free (Modes .clients [fd ]);
1747
1753
Modes .clients [fd ] = NULL ;
1748
1754
1755
+ if (Modes .debug == MODES_DEBUG_NET )
1756
+ printf ("Closing client %d\n" , fd );
1757
+
1749
1758
/* If this was our maxfd, rescan the full clients array to check what's
1750
1759
* the new max. */
1751
1760
if (Modes .maxfd == fd ) {
@@ -1901,21 +1910,35 @@ char *aircraftsToJson(int *len) {
1901
1910
int handleHTTPRequest (struct client * c ) {
1902
1911
char hdr [512 ];
1903
1912
int clen , hdrlen ;
1904
- int keepalive ;
1913
+ int httpver , keepalive ;
1905
1914
char * p , * url , * content ;
1906
1915
char * ctype ;
1907
1916
1908
- /* printf("HTTP request: %s\n", c->buf); */
1917
+ if (Modes .debug == MODES_DEBUG_NET )
1918
+ printf ("\nHTTP request: %s\n" , c -> buf );
1909
1919
1910
1920
/* Minimally parse the request. */
1911
- keepalive = strstr (c -> buf , "keep-alive" ) != NULL ;
1921
+ httpver = (strstr (c -> buf , "HTTP/1.1" ) != NULL ) ? 11 : 10 ;
1922
+ if (httpver == 10 ) {
1923
+ /* HTTP 1.0 defaults to close, unless otherwise specified. */
1924
+ keepalive = strstr (c -> buf , "Connection: keep-alive" ) != NULL ;
1925
+ } else if (httpver == 11 ) {
1926
+ /* HTTP 1.1 defaults to keep-alive, unless close is specified. */
1927
+ keepalive = strstr (c -> buf , "Connection: close" ) == NULL ;
1928
+ }
1929
+
1930
+ /* Identify he URL. */
1912
1931
p = strchr (c -> buf ,' ' );
1913
1932
if (!p ) return 1 ; /* There should be the method and a space... */
1914
1933
url = ++ p ; /* Now this should point to the requested URL. */
1915
1934
p = strchr (p , ' ' );
1916
1935
if (!p ) return 1 ; /* There should be a space before HTTP/... */
1917
1936
* p = '\0' ;
1918
- /* printf("URL: %s\n", url); */
1937
+
1938
+ if (Modes .debug == MODES_DEBUG_NET ) {
1939
+ printf ("\nHTTP keep alive: %d\n" , keepalive );
1940
+ printf ("HTTP requested URL: %s\n\n" , url );
1941
+ }
1919
1942
1920
1943
/* Select the content to send, we have just two so far:
1921
1944
* "/" -> Our google map application.
@@ -1959,6 +1982,9 @@ int handleHTTPRequest(struct client *c) {
1959
1982
keepalive ? "keep-alive" : "close" ,
1960
1983
clen );
1961
1984
1985
+ if (Modes .debug == MODES_DEBUG_NET )
1986
+ printf ("HTTP Reply header:\n%s" , hdr );
1987
+
1962
1988
/* Send header and content. */
1963
1989
if (write (c -> fd , hdr , hdrlen ) == -1 ||
1964
1990
write (c -> fd , content , clen ) == -1 )
@@ -1968,7 +1994,7 @@ int handleHTTPRequest(struct client *c) {
1968
1994
}
1969
1995
free (content );
1970
1996
Modes .stat_http_requests ++ ;
1971
- return 0 ;
1997
+ return ! keepalive ;
1972
1998
}
1973
1999
1974
2000
/* This function polls the clients using read() in order to receive new
0 commit comments