home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / srvstruc.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  28KB  |  807 lines

  1. //
  2. // Structure related defines
  3. //
  4.  
  5. #define SRV_SERVBSIZE(a)                            \
  6.             ((WORD)(a->srvio.packetsize) > (WORD)0  \
  7.             ? (WORD)(a->srvio.packetsize)           \
  8.             : (WORD)512)
  9.  
  10. #define SRV_DEFAULT_SERVBSIZE   512
  11. #define MAX_NETLIBS             16      // Maximum server side net-libs
  12. #define SRV_SERVNETFUNCS    11
  13.  
  14. #ifdef BRIDGE
  15.   #define SRV_CLIENTNETFUNCS    12
  16. #endif
  17.  
  18. typedef long (CDECL *LGFARPROC)();
  19.  
  20. typedef struct srv_handler {
  21.     
  22.   struct srv_handler * previous;
  23.   struct srv_handler * next;
  24.   struct srv_handler * last;
  25.   int (* handler)(void *);
  26.  
  27. } SRV_HANDLER;
  28.  
  29. typedef struct srv_pevents {        
  30.      SRV_HANDLER * srv_attention;
  31.      SRV_HANDLER * srv_connect;
  32.      SRV_HANDLER * srv_disconnect;
  33.      SRV_HANDLER * srv_rpc;
  34.      SRV_HANDLER * srv_language;
  35.      SRV_HANDLER * srv_start;
  36.      SRV_HANDLER * srv_stop;
  37.      SRV_HANDLER * srv_sleep;
  38.      SRV_HANDLER * srv_restart;
  39.      SRV_HANDLER * srv_transmgr;
  40.      SRV_HANDLER * srv_oledb;
  41. } SRV_PEVENTS;
  42.  
  43. typedef struct srv_events {
  44.     int (*srv_hndl_attention)(void *);  // ( SRV_PROC   * )
  45.     int (*srv_hndl_connect)(void *);    // ( SRV_PROC   * )
  46.     int (*srv_hndl_disconnect)(void *); // ( SRV_PROC   * )
  47.     int (*srv_hndl_restart)(void *);    // ( SRV_SERVER * )
  48.     int (*srv_hndl_rpc)(void *);        // ( SRV_PROC   * )
  49.     int (*srv_hndl_sleep)(void *);      // ( SRV_SERVER * )
  50.     int (*srv_hndl_language)(void *);   // ( SRV_PROC   * )
  51.     int (*srv_hndl_start)(void *);      // ( SRV_SERVER * )
  52.     int (*srv_hndl_stop)(void *);    // ( SRV_SERVER * )
  53.     int (*srv_hndl_attention_ack)(void *);  // ( SRV_PROC * )
  54.     int (*srv_hndl_transmgr)(void *);    // ( SRV_PROC * )
  55.     int (*srv_hndl_insertexec)(void *);    // ( SRV_PROC * )
  56.     int (*srv_hndl_oledb)(void *);    // ( SRV_PROC * )
  57. } SRV_EVENTS;
  58.  
  59. typedef struct srv_subchannel {
  60.     struct srv_proc * srvproc;
  61.    HANDLE threadHDL;
  62.    THREAD threadID;
  63.     HANDLE ss_handle;
  64.     HANDLE cs_handle;
  65.     HANDLE hEvent;
  66.     BOOL status;
  67.     struct srv_proc * site_srvproc;
  68.     DWORD index;
  69.     struct srv_proc ** master_list;
  70. } SRV_SUBCHANNEL;
  71.  
  72. //
  73. // define structures
  74. //
  75.  
  76. typedef struct translation_info
  77. {
  78.     BOOL flag;                      // data translation flag
  79.     void (*int2)(short*);           // 2-byte integer swap function
  80.     void (*int4)(long*);            // 4-byte integer swap function
  81.     void (*recvflt)(float*);        // receive 8-byte float translation function
  82.     void (*sendflt)(float*);        // send 8-byte float translation function
  83.     void (*recvflt4)(float*);       // receive 4-byte float translation function
  84.     void (*sendflt4)(float*);       // send 4-byte float translation function
  85.     void (*recvchar)(char *, int);  // ASCII translation function
  86.     void (*sendchar)(char *, int);  // ASCII translation function
  87.     void (*twoint4)(char *);        // 2 4-byte integer swap function
  88.     void (*twoint2)(char *);        // 2 2-byte interger swap function
  89. } TRANSLATION_INFO;
  90.  
  91.  
  92. typedef struct srv_params
  93. {
  94.     struct srv_server    * server;
  95.     struct srv_proc      * srvproc;
  96.     struct srv_queuehead * queuehead;
  97.     struct srv_comport     * comport;
  98.     THREAD                 threadID;
  99.     HANDLE                 threadHDL;
  100. } SRV_PARAMS;
  101.  
  102. #if defined( _MSSQLRISC_)
  103.   #pragma pack(2)
  104. #endif
  105.  
  106. //  SRV_LOGIN
  107. //     The (TDS 4.0) login record received from the server client at login time.
  108. //
  109.  
  110. typedef struct srv_loginrec {
  111.     BYTE lhostname[SRV_MAXNAME];    // name of host or generic
  112.     BYTE lhostnlen;         // length of lhostname
  113.     BYTE lusername[SRV_MAXNAME];    // name of user
  114.     BYTE lusernlen;         // length of lusername
  115.     BYTE lpw[SRV_MAXNAME];  // password (plaintext)
  116.     BYTE lpwnlen;           // length of lpw
  117.     BYTE lhostproc[SRV_HOSTIDLEN];     // host process identification
  118.     BYTE lunused[SRV_MAXNAME-SRV_HOSTIDLEN - 6];     // unused
  119.     BYTE lapptype [6];        // Application specific.
  120.     BYTE lhplen;            // length of host process id
  121.     BYTE lint2;             // type of int2 on this host
  122.     BYTE lint4;             // type of int4 on this host
  123.     BYTE lchar;             // type of char
  124.     BYTE lflt;              // type of float
  125.     BYTE ldate;             // type of datetime
  126.     BYTE lusedb;            // notify on exec of use db cmd
  127.     BYTE ldmpld;            // disallow use of dump/load and bulk insert
  128.     BYTE linterface;        // SQL interface type
  129.     BYTE ltype;             // type of network connection
  130.     BYTE spare[7];          // NOTE: Apparently used by System-10
  131.     BYTE lappname[SRV_MAXNAME]; // application name
  132.     BYTE lappnlen;          // length of appl name
  133.     BYTE lservname[SRV_MAXNAME];    // name of server
  134.     BYTE lservnlen;         // length of lservname
  135.     BYTE lrempw[0xff];      // passwords for remote servers
  136.     BYTE lrempwlen;         // length of lrempw
  137.     BYTE ltds[4];           // tds version
  138.     BYTE lprogname[DBPROGNLEN]; // client program name
  139.     BYTE lprognlen;         // length of client program name
  140.     BYTE lprogvers[4];      // client program version
  141.     BYTE lnoshort;          // NEW: auto convert of short datatypes
  142.     BYTE lflt4;             // NEW: type of flt4 on this host
  143.     BYTE ldate4;            // NEW: type of date4 on this host
  144.     BYTE llanguage[SRV_MAXNAME];    // NEW: initial language
  145.     BYTE llanglen;          // NEW: length of language
  146.     BYTE lsetlang;          // NEW: notify on language change
  147.     short slhier;           // NEW: security label hierarchy
  148.     BYTE slcomp[8];         // NEW: security components
  149.     short slspare;          // NEW: security label spare
  150.     BYTE slrole;            // NEW: security login role
  151.     BYTE lcharset[SRV_MAXNAME]; // character set name (unused)
  152.     BYTE lcharsetlen;       // length of character set (unused)
  153.     BYTE lsetcharset;       // notify on character set change (unused)
  154.     BYTE lpacketsize[SRV_PKTLEN]; // length of TDS packets
  155.     BYTE lpacketsizelen;    // length of lpacketsize
  156.     BYTE ldummy[3];         // NEW: pad to longword
  157.  
  158. } SRV_LOGINREC;
  159.  
  160. //
  161. //  SRV_LOGIN_OLDTDS
  162. //     The login record received from "old" TDS 2.0 or 3.4 server clients.
  163. //     The format is basically the same as 4.0, it is just shorter (no server
  164. //     name or password, etc appended at the end).
  165. //
  166. typedef struct srv_login_oldtds {
  167.     BYTE lhostname[SRV_MAXNAME];    // name of host or generic
  168.     BYTE lhostnlen;         // length of lhostname
  169.     BYTE lusername[SRV_MAXNAME];    // name of user
  170.     BYTE lusernlen;         // length of lusername
  171.     BYTE lpw[SRV_MAXNAME];  // password (plaintext)
  172.     BYTE lpwnlen;           // length of lpw
  173.     BYTE lhostproc[SRV_MAXNAME];    // host process identification
  174.     BYTE lhplen;            // length of host process id
  175.     BYTE lint2;             // type of int2 on this host
  176.     BYTE lint4;             // type of int4 on this host
  177.     BYTE lchar;             // type of char
  178.     BYTE lflt;              // type of float
  179.     BYTE ldate;             // type of datetime
  180.     BYTE lusedb;            // notify on exec of use db cmd
  181.     BYTE ldmpld;            // disallow use of dump/load and bulk insert
  182.     BYTE linterface;        // SQL interface type
  183.     BYTE spare[8];          // spare fields
  184.     BYTE lappname[SRV_MAXNAME]; // application name
  185.     BYTE lappnlen;          // length of appl name
  186.     BYTE ldummy;         // pad length to even boundary
  187.  
  188. } SRV_LOGIN_OLDTDS;
  189. #if defined( _MSSQLRISC_)
  190.   #pragma pack()
  191. #endif
  192.  
  193. // Define structure for ODS statistics
  194.  
  195. typedef struct srv_stats {
  196.     int NumReads;
  197.     int NumWrites;
  198. } SRV_STATS;
  199.  
  200.  
  201.  
  202. // Define list elements used in queuing
  203. // network request.
  204.  
  205. typedef struct srv_queuehead {
  206.     struct srv_queuehead * Flink;
  207.     struct srv_queuehead * Blink;
  208.     struct srv_listhead  * ListHead;
  209. } SRV_QUEUEHEAD, *PSRV_QUEUEHEAD;
  210.  
  211.  
  212. typedef struct srv_listhead {
  213.     struct srv_listentry * Flink;
  214.     struct srv_listentry * Blink;
  215.     int    NumListEntries;
  216.     int    NumReadRequest;
  217.     int    MaxQueueLength;
  218.     long   ListLock;
  219.     HANDLE ListEvent;
  220. } SRV_LISTHEAD, *PSRV_LISTHEAD;
  221.  
  222. typedef struct srv_listentry {
  223.     struct srv_listentry * Flink;
  224.     struct srv_listentry * Blink;
  225.     struct srv_proc      * pSrvProc;
  226. } SRV_LISTENTRY, *PSRV_LISTENTRY;
  227.  
  228. // Define routines to manage list entries.
  229.  
  230. //
  231. //  VOID
  232. //  InitializeListHead(
  233. //  PSRV_LISTENTRY ListHead
  234. //      );
  235. //
  236.  
  237. #define InitializeListHead(TYPE, ListHead) (\
  238.     (ListHead)->Flink = (ListHead)->Blink = (TYPE)(ListHead))
  239.  
  240. //
  241. //  BOOLEAN
  242. //  IsListEmpty(
  243. //  PSRV_LISTENTRY ListHead
  244. //      );
  245. //
  246.  
  247. #define IsListEmpty(ListHead) (\
  248.     ( ((ListHead)->Flink == (ListHead)) ? TRUE : FALSE ) )
  249.  
  250. //
  251. //  SRV_LISTENTRY
  252. //  RemoveHeadList(
  253. //  TYPE,
  254. //  TYPE ListHead
  255. //      );
  256. //
  257.  
  258. #define RemoveHeadList(TYPE,ListHead) \
  259.     (TYPE)(ListHead)->Flink;\
  260.     {\
  261.     TYPE FirstEntry;\
  262.         FirstEntry = (ListHead)->Flink;\
  263.     FirstEntry->Flink->Blink = (TYPE)(ListHead);\
  264.         (ListHead)->Flink = FirstEntry->Flink;\
  265.     }
  266.  
  267. //
  268. //  VOID
  269. //  RemoveEntryList(
  270. //  PSRV_LISTENTRY Entry
  271. //      );
  272. //
  273.  
  274. #define RemoveEntryList(Entry) {\
  275.     PSRV_LISTENTRY _EX_Entry;\
  276.         _EX_Entry = (Entry);\
  277.         _EX_Entry->Blink->Flink = _EX_Entry->Flink;\
  278.         _EX_Entry->Flink->Blink = _EX_Entry->Blink;\
  279.     }
  280.  
  281. //
  282. //  VOID
  283. //  InsertTailList(
  284. //  PSRV_LISTHEAD  ListHead,
  285. //  PSRV_LISTENTRY Entry
  286. //      );
  287. //
  288.  
  289. #define InsertTailList(ListHead,Entry) \
  290.     (Entry)->Flink = (ListHead);\
  291.     (Entry)->Blink = (ListHead)->Blink;\
  292.     (ListHead)->Blink->Flink = (Entry);\
  293.     (ListHead)->Blink = (Entry);\
  294.     InterlockedIncrement(&(ListHead)->NumListEntries);
  295.  
  296. //
  297. //  VOID
  298. //  InsertHeadList(
  299. //  PSRV_LISTHEAD  ListHead,
  300. //  PSRV_LISTENTRY Entry
  301. //      );
  302. //
  303.  
  304. #define InsertHeadList(ListHead,Entry) \
  305.     (Entry)->Flink = (ListHead)->Flink;\
  306.     (Entry)->Blink = (ListHead);\
  307.     (ListHead)->Flink->Blink = (Entry);\
  308.     (ListHead)->Flink = (Entry);\
  309.     InterlockedIncrement(&(ListHead)->NumListEntries);
  310.  
  311. //
  312. //  VOID
  313. //  InsertHeadQueue(
  314. //  PSRV_QUEUEHEAD  ListHead,
  315. //  PSRV_QUEUEHEAD  Entry
  316. //      );
  317. //
  318.  
  319. #define InsertHeadQueue(ListHead,Entry) \
  320.     (Entry)->Flink = (ListHead)->Flink;\
  321.     (Entry)->Blink = (ListHead);\
  322.     (ListHead)->Flink->Blink = (Entry);\
  323.     (ListHead)->Flink = (Entry);
  324.  
  325. //
  326. //  VOID
  327. //  InsertTailQueue(
  328. //  PSRV_QUEUEHEAD  ListHead,
  329. //  PSRV_QUEUEHEAD  Entry
  330. //      );
  331. //
  332.  
  333. #define InsertTailQueue(ListHead,Entry) \
  334.     (Entry)->Flink = (ListHead);\
  335.     (Entry)->Blink = (ListHead)->Blink;\
  336.     (ListHead)->Blink->Flink = (Entry);\
  337.     (ListHead)->Blink = (Entry);
  338.  
  339. //
  340. //  VOID
  341. //  RemoveEntryQueue(
  342. //  PSRV_QUEUEHEAD Entry
  343. //      );
  344. //
  345.  
  346. #define RemoveEntryQueue(Entry) {\
  347.     PSRV_QUEUEHEAD _EX_Entry;\
  348.         _EX_Entry = (Entry);\
  349.         _EX_Entry->Blink->Flink = _EX_Entry->Flink;\
  350.         _EX_Entry->Flink->Blink = _EX_Entry->Blink;\
  351.     }
  352.  
  353.  
  354. // Configuration structure.
  355.  
  356. typedef struct srv_config {
  357.     unsigned  connections;          // maximum allowed client connections
  358.     unsigned  stacksize;            // stack size of new threads created
  359.     BOOL      log_file_open;        // flag indicating log file open
  360.     HANDLE    log_handle;           // handle of openned log file
  361.     char      log_file_name[SRV_MAXFILENAME];    // name of log file
  362.     BOOL      print_recv;           // dump reads to screen
  363.     BOOL      print_send;           // dump sends to screen
  364.     BOOL      remote_access;        // flag indicating remote server access
  365.     unsigned  max_remote_sites;     // simultaneous remote sites accessing
  366.     unsigned  max_remote_connections;   // maximum allowed in/out remote connections
  367.     WORD      numConnectsPerThread; // Number of connections to monitor per network thread
  368.     WORD      MaxWorkingThreads;    // Max number of working threads
  369.     WORD      MinWorkingThreads;    // Min Number of working threads
  370.     WORD      ConcurrentThreads;    // Min Number of working threads
  371.     DWORD     WorkingThreadTimeout; // Time to wait before exiting when idle
  372.     unsigned  max_packets;          // maximum number of network packets buffered
  373.     //
  374.     // Multi Server Side Net-Library support
  375.     //
  376.     WORD      numNetLibs;
  377.     WORD      spare;
  378.     LGFARPROC SSNetLibs[MAX_NETLIBS][SRV_SERVNETFUNCS];         // NetLib Function ptrs
  379.     HANDLE    SSModules[MAX_NETLIBS];                           // NetLib Module handles
  380.     char      connect_names[MAX_NETLIBS][SRV_MAXFILENAME];      // NetLib connection names
  381.     char      connect_dlls[MAX_NETLIBS][SRV_MAXFILENAME];       // NetLib names
  382.     char      connect_versions[MAX_NETLIBS][SRV_MAXFILENAME];   // NetLib versions
  383.     char      server_name[SRV_MAXFILENAME]; // Server name
  384.     BOOL      local_only;           // flag indicating local access only
  385.     BOOL      unpack_rpc;           // flag indicating if RPCs should be unpacked
  386.     unsigned  max_packetsize;       // maximum network packet size
  387.     unsigned  dflt_packetsize;        // The default packet size.
  388.  
  389.     int       ThreadPriority;  // Priority of thread in class.
  390.     BOOL ansi;    // flag indicating if ANSI codepage is used
  391.     BYTE      tdsversion[4];
  392.     BYTE      progversion[4];
  393.     DWORD     threadaffinity;            // thread affinity option
  394. #ifdef BRIDGE
  395.     HANDLE      CSModule;                       // Client NetLib Module handle
  396.     LGFARPROC   CSNetLib[SRV_CLIENTNETFUNCS];   // NetLib Function ptrs
  397.     char        client_name[SRV_MAXFILENAME];   // Client side name
  398.     BOOL        bAuditConnects;                 // flag indicating if connects should be logged
  399. #endif
  400. } SRV_CONFIG;
  401.  
  402. //
  403. //  SRV_TDSHDR
  404. //  The first 8 bytes of each network packet constitute the packet
  405. //  header.
  406. //
  407. typedef struct srv_tdshdr {
  408.     BYTE        type;       // io packet type
  409.     BYTE        status;     // io packet status
  410.     DBUSMALLINT length;     // io packet length
  411.     DBUSMALLINT channel;    // io packet subchannel
  412.     BYTE        packet;     // io packet number
  413.     BYTE        window;     // io packet window size
  414.  
  415. } SRV_TDSHDR;
  416.  
  417. //  SRV_INPUTBUF
  418. //  This structure maintains the read information when
  419. //  pre-reading packets.
  420. //
  421.  
  422. typedef struct srv_inputbuf {
  423.     BYTE * pBuffer;
  424.     DWORD  ioStatus;
  425.     DWORD  ioRecvCnt;
  426.     struct srv_inputbuf * pNext;
  427. } SRV_INPUTBUF;
  428.  
  429. // SRV_COMPORT_QUEUE
  430. // Queue entry for completion port requests.
  431. //
  432. typedef struct srv_comport_queue
  433. {
  434.     struct srv_comport_queue*    Flink;
  435.     struct srv_comport_queue*    Blink;
  436. } SRV_COMPORT_QUEUE;
  437.  
  438. // SRV_COMPORT_BUF
  439. //    Description of a buffer passed through the srv_post_completion_queue
  440. //  entry point. These buffers are typically posted by the server to
  441. //    perform work on a worker thread that can't be handled by the currently
  442. //    executing thread.
  443. //
  444. typedef struct srv_comportbuf 
  445. {
  446.     SRV_COMPORT_QUEUE    queue;
  447.  
  448.     // Overlapped structure passed through srv_post_completion_queue
  449.     // overlapped.Offset contains the address of this structure such that
  450.     // 
  451.     OVERLAPPED    overlapped;
  452.     DWORD        message_size;
  453.     BYTE        message [1];
  454. } SRV_COMPORT_BUF;
  455.  
  456. // WARNING! There is code that assumes it can get to the "last" input
  457. // buffer by looking at the current->pNext buffer. (i.e. It assumes
  458. // SRV_NUMINPUTBUFS == 2).
  459. //
  460. #define SRV_NUMINPUTBUFS 2
  461.  
  462. //
  463. //  SRV_IO
  464. //  This is the data structure used for reading and writing client
  465. //  connection data for a particular server task.
  466. //
  467. typedef struct srv_io {
  468.     void * server_ep;       // server side endpoint
  469. #ifdef BRIDGE
  470.     void * client_ep;       // client side endpoint
  471.     BOOL       fCSerror;        // flag indicate client-side error
  472. #endif
  473.     HANDLE      cs_sub_handle;  // client-side subchannel local handle
  474.     BYTE  * outbuff;        // send: start of send buffer
  475.     BYTE  * p_outbuff;      // send: next place in buffer
  476.     WORD        n_outbuff;      // send: room left in send buffer
  477.     BYTE  * inbuff;         // recv: start of read buffer
  478.     BYTE  * p_inbuff;       // recv: next place in buffer
  479.     WORD        n_inbuff;       // recv: room left in read buffer
  480.     int         SQLspanned;     // flag indicating that the SQL command
  481.                                 //  has spanned more that 1 network buffer.
  482.     int cbflag;                      // flag indicating that a client buffer is
  483.                                 //  available.
  484.     DBUSMALLINT channel;        // io packet subchannel
  485.     BYTE        packet;         // io packet number
  486.     BYTE        window;         // io packet window size
  487.     HANDLE      ioEvent;        // io event handle
  488.     OVERLAPPED  ioOverlapped;   // io overlapped structure.
  489.     SRV_INPUTBUF * pNextInBuf;  // current io input buffer index
  490.     SRV_INPUTBUF   ioInputBuffers[SRV_NUMINPUTBUFS]; // io input buffers
  491.     HANDLE      ss_sub_handle;  // server-side subchannel local handle
  492.     WORD packetsize;        // TDS packet size
  493. } SRV_IO;
  494.  
  495. //
  496. //  SRV_COLDESC: column description array (used by srv_describe & srv_sendrow)
  497. //
  498. typedef struct srv_coldesc {
  499.     unsigned long otype;        // output data type
  500.     unsigned long olen;         // length
  501.     unsigned long itype;        // input data type
  502.     unsigned long ilen;         // length
  503.     BYTE    *data;        // data buffer address
  504.     DBINT    user_type;        // user-defined data type
  505.     BYTE     precision;     // precision
  506.     BYTE     scale;        // scale
  507. } SRV_COLDESC;
  508.  
  509. //
  510. //  SRV_RPCp: RPC parameter information
  511. //
  512. typedef struct srv_rpcp {
  513.     BYTE          len;          // length of RPC parameter name
  514.     BYTE    * rpc_name;     // pointer to the RPC parameter name
  515.     BYTE          status;       // return status, 1 = passed by reference
  516.     unsigned long user_type;    // User-defined data type
  517.     BYTE          type;         // data type
  518.     unsigned long maxlen;       // maximum possible data length
  519.     unsigned long actual_len;   // actual data length
  520.     void    * value;        // the actual data
  521. } SRV_RPCp;
  522.  
  523. typedef struct srv_comport {
  524.     HANDLE hdl;
  525.     DWORD  cpu;
  526. } SRV_COMPORT;
  527.  
  528. //
  529. //  SRV_PROC:   This is the main connection structure
  530. //
  531. typedef struct srv_proc 
  532. {
  533.     WORD          tdsversion;   // version of tds detected from client
  534.                                 //   0x3400 = 3.4, 0x4000 = 4.0
  535.     WORD          status;       // status of this SRV_PROC
  536.     SRV_IO        srvio;        // I/O structure of srvproc
  537.     SRV_LOGINREC  login;        // login record received from the client
  538.     void        * langbuff;     // pointer to language buffer
  539.     unsigned long langlen;      // length of language buffer
  540.     unsigned int  event;        // event variable
  541.     void        * server;       // pointer to associated SRV_SERVER structure
  542.     char        * threadstack;  // stack pointer of event thread stack
  543.     THREAD        threadID;     // thead ID associated with this SRV_PROC
  544.     HANDLE        threadHDL;    // thread handle for resume and suspend
  545.     HANDLE        iowakeup;     // event handle to wait on for overlapped io
  546.                                 // and more. Passed on to SQL Server and netlibs.
  547.     HANDLE        exited;       // semaphore indicating that thread
  548.                                 //  associated with this SRV_PROC has exited
  549.     DBINT         rowsent;      // # of rows sent to client
  550.     SRV_COLDESC * coldescp;     // pointer to column description array
  551.     DBUSMALLINT   coldescno;    // count of column descriptions
  552.     BYTE        * colnamep;     // pointer to column name list
  553.     WORD          colnamelen;   // length of column name list
  554.     void        * userdata;     // pointer to user's private data area
  555.     void        * event_data;   // pointer to event data area
  556.     BYTE          serverlen;    // length of server name
  557.     BYTE        * servername;   // name of server
  558.     
  559.     //  RPC info
  560.     //
  561.     BYTE           rpc_active;          // flag indicating active RPC (TRUE=active)
  562.     BYTE           rpc_server_len;      // length of RPC server name
  563.     BYTE         * rpc_server;          // name of RPC server
  564.     BYTE           rpc_database_len;    // length of RPC database name
  565.     BYTE         * rpc_database;        // name of RPC database
  566.     BYTE           rpc_owner_len;       // length of RPC owner name
  567.     BYTE         * rpc_owner;           // name of RPC owner
  568.     BYTE           rpc_proc_len;        // length of RPC or stored procecedure name
  569.     BYTE         * rpc_proc_name;       // name of RPC or stored procedure
  570.     unsigned int   rpc_proc_number;     // number of RPC "procedure_name;number"
  571.     unsigned int   rpc_linenumber;      // line number batch error occurred on.
  572.     unsigned short rpc_options;         // recompile option flag (bit 0)
  573.     unsigned short rpc_num_params;      // number of RPC parameters
  574.     SRV_RPCp    ** rpc_params;          // array of pointers to each RPC paramater
  575.     
  576.     // Return information for non-remote procedure call client command.
  577.     // This information is provided by the function srv_returnval().
  578.     // flag indicating active non-RPC values (TRUE = active)
  579.     //
  580.     BYTE non_rpc_active;
  581.  
  582.     // number of non-RPC parameters
  583.     //
  584.     unsigned short non_rpc_num_params;
  585.  
  586.     // array of pointers to each non-RPC paramater
  587.     //
  588.     SRV_RPCp ** non_rpc_params;
  589.     
  590.     // temporary work buffer
  591.     //
  592.     char temp_buffer[100];
  593.  
  594.     // array of subchannel structures
  595.     //
  596.     SRV_SUBCHANNEL * (*subprocs);
  597.  
  598.     // Data Translation information
  599.     //
  600.     TRANSLATION_INFO     translation_info;
  601.     struct srv_listentry IOListEntry;
  602.     struct srv_listentry CommandListEntry;
  603.     PSRV_LISTHEAD        pNetListHead;
  604.     BOOL                 bNewPacket;
  605.     long                 StatusCrit;    // critical section to check attentions
  606.     void               * serverdata;    // private data area used ONLY by SQL Server
  607.     SRV_SUBCHANNEL     * subchannel;
  608.  
  609.     // Pre && Post Handler pointers
  610.     //
  611.     SRV_PEVENTS * pre_events;
  612.     SRV_PEVENTS * post_events;
  613.  
  614.     // current position in language buffer used by processRPC
  615.     // 
  616.     void * p_langbuff;    
  617.  
  618.     BOOL    fSecureLogin;
  619.  
  620.     // Set by the server when making an outbound call to an XP.
  621.     //
  622.     BOOL    fInExtendedProc;
  623.  
  624.     // If TRUE indicates the current buffer is from
  625.     // srv_post_completion_queue and the buffer should be
  626.     // deallocated when the current work is completed.  If
  627.     // FALSE the current buffer came from the network and a
  628.     // new read should be posted on the net.
  629.     //
  630.     unsigned    fLocalPost:1;
  631.  
  632.     // If TRUE an XP associated with this srvproc made a call back into
  633.     // the server on a bound connection. This flag is used to allow the
  634.     // calling session to wait for logout processing of the XP to complete
  635.     //
  636.     unsigned    fMadeBoundCall:1;
  637.  
  638.     // Filler to align after flags above.
  639.     //
  640.     unsigned    uFill1:30;
  641.  
  642.     // List of requests posted using srv_post_completion_queue. Entries are
  643.     // dynamically allocated inside srv_post_completion_queue and enqueued
  644.     // in netIOCompletionRoutine. After the request has been processed the
  645.     // entry is removed from this queue and deallocated.
  646.     //
  647.     // NOTE: Must hold SRV_PROC spinlock while altering queue.
  648.     //
  649.     SRV_COMPORT_QUEUE    comport_queue;
  650.  
  651.     // Data pointers reserved for the Starfighter team
  652.     //
  653.     void * pSF1;    // Currently in use by SQLTrace
  654.     void * pSF2;    // Reserved
  655.  
  656.     // Pre and Post handler semephores used during handler instals
  657.     // and deinstals.
  658.     //
  659.     HANDLE hPreHandlerMutex;
  660.     HANDLE hPostHandlerMutex;
  661.     BOOL   bSAxp;        // Used by XP's to determine if running as SA
  662.  
  663. } SRV_PROC;
  664.  
  665. typedef struct srv_control 
  666. {
  667.     unsigned int status;        // status of process
  668.     unsigned int connects;      // current number of connections
  669.  
  670.     SRV_PROC * (* srvprocs);    // array of SRV_PROC connection structures
  671.  
  672.     // semaphore indicating that the connects counter is being accessed or
  673.     // modified
  674.     //
  675.     HANDLE connects_sem;
  676.     
  677.     // semaphore indicating that thread has started
  678.     //
  679.     HANDLE start_sem;
  680.     
  681.     // semaphore indicating that some event has occurred
  682.     //
  683.     HANDLE event_sem;
  684.     
  685.     // semaphore indicating that log file is being written to
  686.     //
  687.     HANDLE log_sem;
  688.     
  689.     // shutdown critical section
  690.     //
  691.     long ShutDownCrit;
  692.  
  693.     // Network list critical section
  694.     //
  695.     long NetQueueCrit;
  696.  
  697.     // Thread Pool critical section
  698.     //
  699.     long ThreadPoolCrit;
  700.  
  701.     // print screen critical section
  702.     //
  703.     long ScrnPrnt;
  704.  
  705.     unsigned int remote_sites;      // current number of remote sites connected
  706.     unsigned int remote_connects;   // current number of in/out remote connections
  707.  
  708.     // semaphore indicating that the remote sites counter is being accessed or
  709.     // modified
  710.     //
  711.     HANDLE remote_sites_sem;
  712.  
  713.     // semaphore indicating that the remote connections counter is being accessed or
  714.     // modified
  715.     //
  716.     HANDLE remote_connects_sem;
  717.  
  718.     // network request queue list
  719.     //
  720.     SRV_QUEUEHEAD netQueueList;
  721.     int           numNetQueueEntries;
  722.     int           maxNetQueueEntries;
  723.  
  724.     // command queue list
  725.     //
  726.     PSRV_LISTHEAD CommandQueueHead;
  727.  
  728.     // Server statistics.
  729.     //
  730.     SRV_STATS   Stats;
  731.  
  732.     DWORD * pSharedCounter;
  733.  
  734.     HANDLE srvproc_mutex;
  735.  
  736.     DWORD  dwWorkingThreadCnt;
  737.     DWORD  maxWorkingThreadCnt;
  738.  
  739.     SRV_COMPORT *comport;
  740.     BYTE   num_comports;
  741.  
  742.     BYTE   ProcessorCnt;
  743.  
  744. } SRV_CONTROL;
  745.  
  746. typedef struct srv_server {
  747.     LGFARPROC  SSNetLib[SRV_SERVNETFUNCS];  // Server Side NetLib functions
  748.     HANDLE     SSModule;                    // Server Side DLL
  749.     DWORD      ep_size;
  750.     void * listen_ep;
  751. #ifdef BRIDGE
  752.     LGFARPROC CSNetLib[SRV_CLIENTNETFUNCS]; // Client Side NetLib functions
  753.     HANDLE    CSModule;                     // Client Side DLL
  754.     char      client_name[SRV_MAXFILENAME];
  755. #endif
  756.     THREAD net_threadID;        // thead ID of client network event thread
  757.     HANDLE net_threadHDL;       // thread handle for resume and suspend
  758.  
  759.     //
  760.     // connection information
  761.     //
  762.     char connect_name[SRV_MAXFILENAME];
  763.     char connect_dll[SRV_MAXFILENAME];
  764.     char connect_version[SRV_MAXFILENAME];
  765.  
  766.     //
  767.     // temporary work buffer
  768.     //
  769.     char temp_buffer[100];
  770.     //
  771.     // server configuration information
  772.     //
  773.     SRV_CONFIG config;
  774.     // server control information
  775.     //
  776.     SRV_CONTROL * control;
  777.  
  778.     // define the event handlers         
  779.     //
  780.     SRV_EVENTS * events;
  781.  
  782.     // Pre && Post Handler pointers
  783.     SRV_PEVENTS * pre_events;
  784.     SRV_PEVENTS * post_events;
  785.  
  786.     // Pre and Post handler semephores
  787.     //
  788.     HANDLE hPreHandlerMutex;    // Single writer
  789.     HANDLE hPostHandlerMutex;
  790.     HANDLE hPreHandlerSem;      // Multiple reader
  791.     HANDLE hPostHandlerSem;
  792.  
  793. } SRV_SERVER;
  794.  
  795. // Private structure used to export server entry points as ODS callbacks
  796. // for SQLServer use only.
  797. //
  798. typedef struct ods_callbacks
  799. {
  800.     int (*sql_getbindtoken) (void*, char*);
  801.     void (*sql_getdtcxact) (void*, void**);
  802.     int (*sql_startinexec) (void*);
  803.     void (*sql_stopinexec) (void*);
  804.     // Place new callbacks at the end of the structure.
  805.  
  806. } ODS_CALLBACKS;
  807.