home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / mweb / MWEB Utils / ws295sdk.exe / Ws2sdkzp.exe / SAMPLES / WS2CHAT / WS2CHAT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-06  |  8.1 KB  |  283 lines

  1. /*++
  2.  
  3. Copyright (c) 1995 Intel Corp
  4.  
  5. Module Name:
  6.  
  7.     ws2chat.h
  8.  
  9. Abstract:
  10.  
  11.     This module defines the data structures and constants
  12.     for the WinSock 2 sample chat application.
  13.  
  14. --*/
  15.  
  16. #ifndef _ws2chat_H
  17. #define _ws2chat_H
  18.  
  19. #include "nowarn.h"  /* turn off benign warnings */
  20. #ifndef _WINSOCKAPI_
  21. #define _WINSOCKAPI_   /* Prevent inclusion of winsock.h in windows.h */
  22. #endif
  23. #include <winsock2.h>
  24.  
  25. #include "nowarn.h"  /* some warnings may have been turned back on */
  26. #include "queue.h"
  27.  
  28. // turn off "unreferenced formal parameter" warning
  29. #pragma warning(disable: 4100)
  30.  
  31.  
  32.  
  33. //
  34. // Manifest Constants
  35. //
  36.  
  37.  
  38. // UI/MDI
  39. #define MAIN_MENU_POS         1
  40. #define CLIENT_WINDOW_ID      1
  41.  
  42. #define EC_SEND_CHILD         0
  43. #define EC_RECV_CHILD         1
  44.  
  45. #define IDM_CONNECT           10
  46. #define IDM_CLOSE             12
  47. #define IDM_EXIT              13
  48. #define IDM_TILE              30
  49. #define IDM_CASCADE           31
  50. #define IDM_ARRANGE           32
  51. #define IDM_CLOSEALL          33
  52. #define IDM_CLEAR_SENDBUFFER  34
  53. #define IDM_CLEAR_RECVBUFFER  35
  54. #define IDM_FIRSTCHILD        100
  55.  
  56. // For some reason, 30k is the most characters you can have in an edit
  57. // control at once.  This keeps us from going over.
  58. #define MAX_EC_TEXT 25500
  59.  
  60. // resource constants
  61. #define IDC_SUBJECT           1000
  62. #define IDC_CALLEENAME        1001
  63. #define IDC_CALLERNAME        1002
  64. #define IDC_FAM_LB            1003
  65. #define IDC_INET_ADDRESS      1004
  66. #define IDC_INET_PORT         1005
  67. #define IDC_ADDRESS           1006
  68. #define IDC_LISTEN_PORT       1007
  69. #define IDC_SELECTOR          1008
  70.  
  71. #define IDC_STATIC            -1
  72.  
  73. // data lengths
  74. #define NAME_LEN              20
  75. #define ADDR_LEN              40
  76. #define SUB_LEN               80
  77. #define MSG_LEN               200
  78. #define TITLE_LEN             40
  79. #define BUFFER_LENGTH         1024
  80.  
  81. // various stuff
  82. #define MAX_SOCKADDR_LEN      512
  83. #define MAX_LISTENING_SOCKETS 64
  84. #define CONN_WND_EXTRA        8
  85. #define GWL_CONNINFO          0
  86. #define GWL_OLDEDITPROC       4
  87. #define NO_MAX_MSG_SIZE       0xffffffff
  88. #define MAX_ERROR_TEXT        64
  89.  
  90. // what kind of send?
  91. #define OVERLAPPED_IO         0
  92. #define NON_OVERLAPPED_IO     1
  93.  
  94. // chat return values
  95. #define CHAT_OK               0
  96. #define CHAT_ERROR            1
  97. #define CHAT_CLOSED           2
  98. #define CHAT_WOULD_BLOCK      3
  99. #define CHAT_ABORTED          4
  100.  
  101. // for Internet connections
  102. #define INET_ADDR_LEN         64
  103. #define INET_PORT_LEN         5
  104. #define INET_DEFAULT_PORT     9009
  105.  
  106. // for ATM connections
  107. #define ATM_BHLI_INFO_LEN     8
  108. #define ATM_DEFAULT_BHLI_INFO "ws2chat1"
  109.  
  110. // user message values
  111. #define USMSG_ACCEPT          WM_USER+1
  112. #define USMSG_CONNECT         WM_USER+2
  113. #define USMSG_TEXTOUT         WM_USER+3
  114.  
  115. // version of Winsock we need
  116. #define VERSION_MAJOR         2
  117. #define VERSION_MINOR         0
  118.  
  119. // quality of Service
  120. #define TOKENRATE             100
  121. #define QOS_UNSPECIFIED       (DWORD)-1
  122.  
  123.  
  124.  
  125. //
  126. // Types and Data Structures
  127. //
  128.  
  129. typedef struct _CONNDATA CONNDATA, *PCONNDATA;
  130. typedef struct _OUTPUT_REQUEST OUTPUT_REQUEST, *POUTPUT_REQUEST;
  131.  
  132. // structure created by the user interface and passed to the
  133. // input/output thread -- tells the I/O thread what to send and how to
  134. // send it.
  135. struct _OUTPUT_REQUEST {
  136.     int             Type;       // OVERLAPPED_IO or NON_OVERLAPPED_IO
  137.     WSABUF          Buffer;     // holds the buffer (pointer) and size
  138.     char            Character;  // for one-character ouput events
  139.     PCONNDATA       ConnData;   // data for the associated connection
  140.     LPWSAOVERLAPPED Overlapped; // NULL if not an overlapped send
  141. };
  142.  
  143. // structure for storing data unique to each connection.
  144. struct _CONNDATA {
  145.  
  146.                     // the socket for the connection
  147.     SOCKET          Socket;
  148.  
  149.                     // string containing the name of the user (only
  150.                     // valid if user-data is supported by the protocol)
  151.     char            PeerName[NAME_LEN + 1];
  152.  
  153.                     // string containing the subject of the chat
  154.                     // session, as entered by the calling entity
  155.     char            Subject[SUB_LEN + 1];
  156.  
  157.                     // string containing the (human-readable) address
  158.                     // of the connected entity
  159.     char            PeerAddress[ADDR_LEN + 1];
  160.  
  161.                     // handle to thread that takes care of network events
  162.     HANDLE          IOThreadHandle;
  163.  
  164.                     // handle to event signaled when a network event
  165.                     // occurs
  166.     HANDLE          SocketEventObject;
  167.  
  168.                     // handle to event signaled when output is ready
  169.                     // to be shipped
  170.     HANDLE          OutputEventObject;
  171.  
  172.                     // points to a queue used to hold output buffers
  173.     PQUEUE          OutputQueue;
  174.  
  175.                     // handle to window associated with the connection
  176.     HWND            ConnectionWindow;
  177.  
  178.                     // handle to the sending and receiving edit controls
  179.     HWND            SendWindow;
  180.     HWND            RecvWindow;
  181.  
  182.                     // the remote socket address for the connection
  183.     WSABUF          RemoteSockAddr;
  184.  
  185.                     // buffer used by the connecting entity to get
  186.                     // user-data back when the  USMSG_CONNECT is
  187.                     // received
  188.     WSABUF          CalleeBuffer;
  189.  
  190.                     // points to a protocol information struct which
  191.                     // represents the protocol for this connection
  192.     LPWSAPROTOCOL_INFO ProtocolInfo;
  193.  
  194.                     // are we waiting for an FD_WRITE?
  195.     BOOL            WriteOk;
  196.  
  197.                     // How many events the wait in the I/O thread is
  198.                     // waiting on.  Once that thread starts, this will
  199.                     // always be at least 2 -- the SocketEventObject
  200.                     // and the OutputEventObject.
  201.     DWORD           NumEvents;
  202.  
  203.                     // The array of events which the I/O thread is
  204.                     // currently waiting on.  Contains NumEvents entries.
  205.     WSAEVENT        EventArray[WSA_MAXIMUM_WAIT_EVENTS];
  206.  
  207.                     // An array of pointers to output request
  208.                     // structures, indexed in parallel to EventArray,
  209.                     // above. This allows us to associate the events
  210.                     // with the output requests, so we can free the
  211.                     // right memory when the event is signaled.
  212.     POUTPUT_REQUEST OutReqArray[WSA_MAXIMUM_WAIT_EVENTS];
  213.  
  214.                     // The maximum message size we can send on this
  215.                     // socket. This value is either an integer or the
  216.                     // manifest constant NO_MAX_MSG_SIZE.
  217.     DWORD            MaxMsgSize;
  218. };
  219.  
  220. // structure to associate listening sockets with a protocol
  221. // information struct.
  222. typedef struct _LISTENDATA {
  223.     SOCKET             Socket;       // a listening socket
  224.     LPWSAPROTOCOL_INFO ProtocolInfo; // the associated protocol info. struct
  225. } LISTENDATA, *PLISTENDATA;
  226.  
  227.  
  228.  
  229.  
  230. //
  231. // Function prototypes for functions to be used outside of ws2chat.c
  232. //
  233.  
  234. void
  235. OutputString(
  236.     IN HWND RecvWindow,
  237.     IN char *String);
  238.  
  239.  
  240. BOOL
  241. ExtractTwoStrings(
  242.     IN  char *Buffer,
  243.     OUT char *String1,
  244.     IN  char Length1,
  245.     OUT char *String2,
  246.     IN  int  Length2);
  247.  
  248. BOOL
  249. TranslateHex(
  250.     OUT LPVOID Buffer,
  251.     IN  int    BufferLen,
  252.     IN  char   *HexString,
  253.     IN  HWND   WindowHandle);
  254.  
  255. BOOL
  256. PackTwoStrings(
  257.     OUT char *Buffer,
  258.     IN int   BufferLen,
  259.     IN char  *String1,
  260.     IN char  *String2);
  261.  
  262. BOOL
  263. MakeRoom(
  264.     IN HWND EditControl,
  265.     IN int  HowMuch);
  266.  
  267. void
  268. ChatSysError(
  269.     IN char *FailedFunction,
  270.     IN char *InFunction,
  271.     IN BOOL Fatal);
  272.  
  273. //
  274. // Externally-Visible Variables
  275. //
  276.  
  277. extern HANDLE  GlobalInstance;    // Identifies the instance of chat
  278. extern char    ConnClassStr[];    // String to register window class
  279. extern char    ChatClassStr[];    // String to register window class
  280. extern HWND    GlobalFrameWindow; // Chat's main -- or frame -- window
  281.  
  282. #endif // _ws2chat_
  283.