source: main/trunk/greenstone2/runtime-src/src/w32server/netio.h@ 27220

Last change on this file since 27220 was 3810, checked in by sjboddie, 21 years ago

Removed some hard string length limits in local library server code

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 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#include "text_t.h"
29
30/*
31Module Name: Net IO
32Purpose: High level Socket IO and Misc socket routines
33Public Functions:
34 InitNetIO
35 CleanUpNetIO
36
37 GetLocalIP
38 GetLocalName
39
40 CreateListeningSocket
41 AnswerListeningSocket
42 DestroyListeningSocket
43
44 CloseSocket
45
46 GetData
47 GetLine
48
49 SendData
50 SendFile
51*/
52
53//Public Functions
54
55/*
56Function Name: Init Net IO
57Purpose: Initializes the module so calls can be made querying network
58 information for the local macnine.
59Notes: MUST be called before GetLocalIP and GetLocalName
60*/
61
62// returns 0 on success,
63// WSASYSNOTREADY, WSAVERNOTSUPPORTED, or WSAEINVAL on failure
64int InitNetIO();
65
66/*
67Function Name: Cleanup Net IO
68Purpose: Cleans up the module and unloads Winsock
69*/
70void CleanUpNetIO();
71
72/*
73Function Name: Reset Net IO
74Purpose: Resets internal data in NetIO to reflect registry changes, etc.
75*/
76void ResetNetIO();
77
78/*
79Function Name: Get Local IP
80Purpose: Gets the local IP number
81Returns: The local IP number as an double word (4 bytes)
82*/
83DWORD GetLocalIP();
84
85/*
86Function Name: Get Local Name
87Purpose: Gets the local Domain name, or if there is none, then the server
88address in dotted format.
89Returns: A string containing the local address
90*/
91char *GetLocalName(HINSTANCE hInstance);
92
93// returns 0 on success, and a WSA error message on failure.
94// possible error messages include:
95// WSANOTINITIALISED, WSAENETDOWN, WSAEAFNOSUPPORT, WSAEINPROGRESS, WSAEMFILE,
96// WSAENOBUFS, WSAEPROTONOSUPPORT, WSAEPROTOTYPE, WSAESOCKTNOSUPPORT,
97// WSAEADDRINUSE, WSAEINVAL, WSAEISCONN, WSAENOTSOCK, WSAEOPNOTSUPP
98int CreateListeningSocket(int &PortNum, HWND MsgWindow,
99 WORD SocketMsg, SOCKET &ServerSocket);
100
101int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket,
102 SOCKADDR_IN &ClientSockAddr, int AddrLen);
103
104void DestroyListeningSocket(SOCKET &ServerSocket, HWND MsgWindow);
105
106void CloseSocket(SOCKET &TargetSocket);
107
108/*
109Function Name: Get Data
110Purpose: Gets data from a socket with muli-threaded debugging
111Parameters:
112 ClientSocket - The socket to get data from
113 IOBuffer - A pointer to a chunk of memory to put data in
114 IOBufferSize - Size of the buffer
115 ThreadNum - Number of the thread that called this functions used for debugging
116
117Returns: -1 on error, else the number of bytes received
118
119Notes:
120Removed socket error checking because I was unable to isolate what
121errors I was getting when getting a "rude" disconnect
122*/
123int GetData(SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, int ThreadNum);
124
125/*
126Function Name: Get Line
127Purpose: Gets a line of text (ended by a LF (10)) from a socket with buffered
128 input. If the buffer is empty this function fills the buffer, else it
129 just changes an index. Also has the ability to do multi-threaded debuging
130Parameters:
131 OutStr - Varible were output is put
132 ClientSocket - The socket to get data from
133 IOBuffer - A pointer to a chunk of memory to put data in
134 IOBufferSize - Size of the buffer
135 BufferIndex - A zero based index of what charactor in the buffer we're at
136 DataInBuffer - Amount of data in the buffer
137 ThreadNum - Number of the thread that called this functions used for debugging
138
139Returns: -1 on disconnect or error (abort connection), 0 on success
140*/
141int GetLine(text_t &OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize,
142 int &BufferIndex, int &DataInBuffer, int ThreadNum);
143
144/*
145Function Name: Send Data
146Purpose: Sends data to a socket with muli-thread debugging
147Parameters:
148 ClientSocket - The socket to get data from
149 SendBuffer - A pointer to a chunk of memory to put data in
150 NumToSend - Number of bytes to send from buffer
151 ThreadNum - Number of the thread that called this functions used for debugging
152
153Returns: -1 on error, 0 on success
154
155Notes:
156Removed socket error checking because I was unable to isolate what
157errors I was getting when getting a "rude" disconnect
158*/
159int SendData(SOCKET ClientSocket, BYTE *SendBuffer,
160 int NumToSend, int ThreadNum);
Note: See TracBrowser for help on using the repository browser.