source: trunk/gsdl/src/w32server/netio.h@ 2286

Last change on this file since 2286 was 2286, checked in by sjboddie, 23 years ago

Had a bit of a tidy up in the fnord webserver code. The main change of note
was the removal of our reliance on the MAX_URL_SIZE constant. URLs and post
data of any length should now work.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/**********************************************************************
2 *
3 * netio.h
4 * Copyright (C) 1996
5 *
6 * A component of the fnord webserver written by [email protected].
7 *
8 * Altered for use with the Greenstone digital library software by the
9 * New Zealand Digital Library Project at the University of Waikato,
10 * New Zealand.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 *********************************************************************/
27
28/*
29Module Name: Net IO
30Purpose: High level Socket IO and Misc socket routines
31Public Functions:
32 InitNetIO
33 CleanUpNetIO
34
35 GetLocalIP
36 GetLocalName
37
38 CreateListeningSocket
39 AnswerListeningSocket
40 DestroyListeningSocket
41
42 CloseSocket
43
44 GetData
45 GetLine
46
47 SendData
48 SendFile
49*/
50
51//Public definitions
52//Max line size for GetLine
53#define NETIO_MAX_LINE 300
54
55//Public Functions
56
57/*
58Function Name: Init Net IO
59Purpose: Initializes the module so calls can be made querying network
60 information for the local macnine.
61Notes: MUST be called before GetLocalIP and GetLocalName
62*/
63
64// returns 0 on success,
65// WSASYSNOTREADY, WSAVERNOTSUPPORTED, or WSAEINVAL on failure
66int InitNetIO();
67
68/*
69Function Name: Cleanup Net IO
70Purpose: Cleans up the module and unloads Winsock
71*/
72void CleanUpNetIO();
73
74/*
75Function Name: Reset Net IO
76Purpose: Resets internal data in NetIO to reflect registry changes, etc.
77*/
78void ResetNetIO();
79
80/*
81Function Name: Get Local IP
82Purpose: Gets the local IP number
83Returns: The local IP number as an double word (4 bytes)
84*/
85DWORD GetLocalIP();
86
87/*
88Function Name: Get Local Name
89Purpose: Gets the local Domain name, or if there is none, then the server
90address in dotted format.
91Returns: A string containing the local address
92*/
93char *GetLocalName(HINSTANCE hInstance);
94
95// returns 0 on success, and a WSA error message on failure.
96// possible error messages include:
97// WSANOTINITIALISED, WSAENETDOWN, WSAEAFNOSUPPORT, WSAEINPROGRESS, WSAEMFILE,
98// WSAENOBUFS, WSAEPROTONOSUPPORT, WSAEPROTOTYPE, WSAESOCKTNOSUPPORT,
99// WSAEADDRINUSE, WSAEINVAL, WSAEISCONN, WSAENOTSOCK, WSAEOPNOTSUPP
100int CreateListeningSocket(int &PortNum, HWND MsgWindow,
101 WORD SocketMsg, SOCKET &ServerSocket);
102
103int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket,
104 SOCKADDR_IN &ClientSockAddr, int AddrLen);
105
106void DestroyListeningSocket(SOCKET &ServerSocket, HWND MsgWindow);
107
108void CloseSocket(SOCKET &TargetSocket);
109
110/*
111Function Name: Get Data
112Purpose: Gets data from a socket with muli-threaded debugging
113Parameters:
114 ClientSocket - The socket to get data from
115 IOBuffer - A pointer to a chunk of memory to put data in
116 IOBufferSize - Size of the buffer
117 ThreadNum - Number of the thread that called this functions used for debugging
118
119Returns: -1 on error, else the number of bytes received
120
121Notes:
122Removed socket error checking because I was unable to isolate what
123errors I was getting when getting a "rude" disconnect
124*/
125int GetData(SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, int ThreadNum);
126
127/*
128Function Name: Get Line
129Purpose: Gets a line of text (ended by a LF (10)) from a socket with buffered
130 input. If the buffer is empty this function fills the buffer, else it
131 just changes an index. Also has the ability to do multi-threaded debuging
132Parameters:
133 OutStr - Varible were output is put (a length of NETIO_MAX_LINE is assumed)
134 ClientSocket - The socket to get data from
135 IOBuffer - A pointer to a chunk of memory to put data in
136 IOBufferSize - Size of the buffer
137 BufferIndex - A zero based index of what charactor in the buffer we're at
138 DataInBuffer - Amount of data in the buffer
139 ThreadNum - Number of the thread that called this functions used for debugging
140
141Returns: -1 on disconnect or error (abort connection), 0 on success
142*/
143int GetLine(char *OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize,
144 int &BufferIndex, int &DataInBuffer, int ThreadNum);
145
146/*
147Function Name: Send Data
148Purpose: Sends data to a socket with muli-thread debugging
149Parameters:
150 ClientSocket - The socket to get data from
151 SendBuffer - A pointer to a chunk of memory to put data in
152 NumToSend - Number of bytes to send from buffer
153 ThreadNum - Number of the thread that called this functions used for debugging
154
155Returns: -1 on error, 0 on success
156
157Notes:
158Removed socket error checking because I was unable to isolate what
159errors I was getting when getting a "rude" disconnect
160*/
161int SendData(SOCKET ClientSocket, BYTE *SendBuffer,
162 int NumToSend, int ThreadNum);
Note: See TracBrowser for help on using the repository browser.