This file is indexed.

/usr/include/ncbi/connect/ncbi_socketp.h is in libncbi6-dev 6.1.20120620-7.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#ifndef CONNECT___NCBI_SOCKETP__H
#define CONNECT___NCBI_SOCKETP__H

/* $Id: ncbi_socketp.h,v 1.26 2012/05/04 19:04:38 kazimird Exp $
 * ===========================================================================
 *
 *                            PUBLIC DOMAIN NOTICE
 *               National Center for Biotechnology Information
 *
 *  This software/database is a "United States Government Work" under the
 *  terms of the United States Copyright Act.  It was written as part of
 *  the author's official duties as a United States Government employee and
 *  thus cannot be copyrighted.  This software/database is freely available
 *  to the public for use. The National Library of Medicine and the U.S.
 *  Government have not placed any restriction on its use or reproduction.
 *
 *  Although all reasonable efforts have been taken to ensure the accuracy
 *  and reliability of the software and data, the NLM and the U.S.
 *  Government do not and cannot warrant the performance or results that
 *  may be obtained by using this software or data. The NLM and the U.S.
 *  Government disclaim all warranties, express or implied, including
 *  warranties of performance, merchantability or fitness for any particular
 *  purpose.
 *
 *  Please cite the author in any work or product based on this material.
 *
 * ===========================================================================
 *
 * Author:  Anton Lavrentiev
 *
 * File Description:
 *   Private API to define socket structure
 *
 */

#include "ncbi_config.h"
/* OS must be specified in the command-line ("-D....") or in the conf. header
 */
#if !defined(NCBI_OS_UNIX)  &&  !defined(NCBI_OS_MSWIN)
#  error "Unknown OS, must be one of NCBI_OS_UNIX, NCBI_OS_MSWIN!"
#endif /*supported platforms*/

#include <connect/ncbi_socket.h>
#include <connect/ncbi_buffer.h>


/* Pull in a minial set of platform-specific system headers here.
 */

#ifdef NCBI_OS_MSWIN
#  include <winsock2.h>
#else /*NCBI_OS_UNIX*/
#  include <sys/socket.h>
#  include <sys/time.h>
#endif /*NCBI_OS_MSWIN*/

/* Portable error codes.
 */
#include <errno.h>

#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus*/

#ifdef NCBI_OS_MSWIN

typedef SOCKET TSOCK_Handle;    /* NB: same as HANDLE   */
typedef HANDLE TRIGGER_Handle;  /* NB: same as WSAEVENT */

#  ifdef _WIN64
#    pragma pack(push, 4)
#  endif /*_WIN64*/

#  define SOCK_EINTR          WSAEINTR
#  define SOCK_EWOULDBLOCK    WSAEWOULDBLOCK/*EAGAIN*/
#  define SOCK_EADDRINUSE     WSAEADDRINUSE
#  define SOCK_ECONNRESET     WSAECONNRESET
#  define SOCK_EPIPE          WSAESHUTDOWN
#  define SOCK_EAGAIN         WSAEINPROGRESS/*special-case missing in WSA*/
#  define SOCK_EINPROGRESS    WSAEINPROGRESS
#  define SOCK_EALREADY       WSAEALREADY
#  define SOCK_ENOTCONN       WSAENOTCONN
#  define SOCK_ECONNABORTED   WSAECONNABORTED
#  define SOCK_ECONNREFUSED   WSAECONNREFUSED
#  define SOCK_ENETRESET      WSAENETRESET
#  define SOCK_ETIMEDOUT      WSAETIMEDOUT
#  define SOCK_SHUTDOWN_RD    SD_RECEIVE
#  define SOCK_SHUTDOWN_WR    SD_SEND
#  define SOCK_SHUTDOWN_RDWR  SD_BOTH

#else /*NCBI_OS_UNIX*/

typedef int TSOCK_Handle;
typedef int TRIGGER_Handle;

#  define SOCK_EINTR          EINTR
#  define SOCK_EWOULDBLOCK    EWOULDBLOCK
#  define SOCK_EADDRINUSE     EADDRINUSE
#  define SOCK_ECONNRESET     ECONNRESET
#  define SOCK_EPIPE          EPIPE
#  define SOCK_EAGAIN         EAGAIN
#  define SOCK_EINPROGRESS    EINPROGRESS
#  define SOCK_EALREADY       EALREADY
#  define SOCK_ENOTCONN       ENOTCONN
#  define SOCK_ECONNABORTED   ECONNABORTED
#  define SOCK_ECONNREFUSED   ECONNREFUSED
#  define SOCK_ENETRESET      ENETRESET
#  define SOCK_ETIMEDOUT      ETIMEDOUT

#  ifndef SHUT_RD
#    define SHUT_RD           0
#  endif /*SHUT_RD*/
#  define SOCK_SHUTDOWN_RD    SHUT_RD
#  ifndef SHUT_WR
#    define SHUT_WR           1
#  endif /*SHUT_WR*/
#  define SOCK_SHUTDOWN_WR    SHUT_WR
#  ifndef SHUT_RDWR
#    define SHUT_RDWR         2
#  endif /*SHUT_RDWR*/
#  define SOCK_SHUTDOWN_RDWR  SHUT_RDWR

#endif /*NCBI_OS_MSWIN*/

#if   defined(ENFILE)
#  define SOCK_ETOOMANY       ENFILE
#elif defined(EMFILE)
#  define SOCK_ETOOMANY       EMFILE
#elif defined(WSAEMFILE)
#  define SOCK_ETOOMANY       WSAEMFILE
#elif defined(EINVAL)
#  define SOCK_ETOOMANY       EINVAL
#else
#  define SOCK_ETOOMANY       0
#endif


#if 0/*defined(__GNUC__)*/
typedef ESwitch    EBSwitch;
typedef EIO_Status EBIO_Status;
#else
typedef unsigned   EBSwitch;
typedef unsigned   EBIO_Status;
#endif


typedef enum {
    eListening = 0,
    eTrigger   = 1,
    eSocket    = 2,
    eDatagram  = 3/*2|1*/
} ESOCK_Type;

typedef unsigned TBSOCK_Type;


/* Event trigger
 */
typedef struct TRIGGER_tag {
    TRIGGER_Handle     fd;      /* OS-specific trigger handle                */
    unsigned int       id;      /* the internal ID (cf. "s_ID_Counter")      */

    union {
        volatile void* ptr;     /* trigger state (UNIX only, otherwise MBZ)  */
        int            int_[2]; /* pointer storage area w/proper alignment   */
    } isset;

    /* type, status, EOF, log, read-on-write etc bit-field indicators */
    TBSOCK_Type         type:2; /* eTrigger                                  */
    EBSwitch             log:2; /* how to log events                         */
    EBSwitch          r_on_w:2; /* MBZ                                       */
    EBSwitch        i_on_sig:2; /* eDefault                                  */

    EBIO_Status     r_status:3; /* MBZ (NB: eIO_Success)                     */
    unsigned/*bool*/     eof:1; /* MBZ                                       */
    EBIO_Status     w_status:3; /* MBZ (NB: eIO_Success)                     */
    unsigned/*bool*/ pending:1; /* MBZ                                       */

    unsigned        reserved:16;/* MBZ                                       */

#ifdef NCBI_OS_UNIX
    int                out;     /* write end of the pipe                     */
#endif /*NCBI_OS_UNIX*/
} TRIGGER_struct;


/* Sides of socket
 */
typedef enum {
    eSOCK_Server = 0,
    eSOCK_Client = 1
} ESOCK_Side;

typedef unsigned EBSOCK_Side;


/* Listening socket [must be in one-2-one binary correspondene with TRIGGER]
 */
typedef struct LSOCK_tag {
    TSOCK_Handle     sock;      /* OS-specific socket handle                 */
    unsigned int     id;        /* the internal ID (see also "s_ID_Counter") */

    unsigned int     n_accept;  /* total number of accepted clients          */
    unsigned short   away;      /* MSWIN: run-away connect warning counter   */
    unsigned short   port;      /* port on which listening (host byte order) */

    /* type, status, EOF, log, read-on-write etc bit-field indicators */
    TBSOCK_Type         type:2; /* eListening                                */
    EBSwitch             log:2; /* how to log events and data for this socket*/
    EBSwitch          r_on_w:2; /* MBZ                                       */
    EBSwitch        i_on_sig:2; /* eDefault                                  */

    EBIO_Status     r_status:3; /* MBZ (NB: eIO_Success)                     */
    unsigned/*bool*/     eof:1; /* MBZ                                       */
    EBIO_Status     w_status:3; /* MBZ (NB: eIO_Success)                     */
    unsigned/*bool*/ pending:1; /* MBZ                                       */

    EBSOCK_Side         side:1; /* MBZ (NB: eSOCK_Server)                    */
    unsigned/*bool*/    keep:1; /* whether to keep OS handle upon close      */
#ifndef NCBI_OS_MSWIN
    unsigned        reserved:14;/* MBZ                                       */
#else
    unsigned        reserved:11;/* MBZ                                       */
    unsigned        readable:1; /* =1 if known to have a pending accept      */
    unsigned          unused:2; /* MBZ                                       */

    WSAEVENT         event;     /* event bound to I/O                        */
#endif /*!NCBI_OS_MSWIN*/

    void*            context;   /* per-server credentials                    */

#ifdef NCBI_OS_UNIX
    char             path[1];   /* must go last                              */
#endif /*NCBI_OS_UNIX*/
} LSOCK_struct;


/* Socket [it must be in 1-2-1 binary correspondence with LSOCK above]
 */
typedef struct SOCK_tag {
    TSOCK_Handle     sock;      /* OS-specific socket handle                 */
    unsigned int     id;        /* the internal ID (see also "s_ID_Counter") */

    /* connection point */
    unsigned int     host;      /* peer host (network byte order)            */
    unsigned short   port;      /* peer port (host byte order)               */
    unsigned short   myport;    /* this socket's port number, host byte order*/

    /* type, status, EOF, log, read-on-write etc bit-field indicators */
    TBSOCK_Type         type:2; /* |= eSocket ({ eSocket | eDatagram })      */
    EBSwitch             log:2; /* how to log events and data for this socket*/
    EBSwitch          r_on_w:2; /* enable/disable automatic read-on-write    */
    EBSwitch        i_on_sig:2; /* enable/disable I/O restart on signals     */

    EBIO_Status     r_status:3; /* read  status:  eIO_Closed if was shut down*/
    unsigned/*bool*/     eof:1; /* Stream sockets: 'End of file' seen on read
                                   Datagram socks: 'End of message' written  */
    EBIO_Status     w_status:3; /* write status:  eIO_Closed if was shut down*/
    unsigned/*bool*/ pending:1; /* =1 if connection is still initing         */

    EBSOCK_Side         side:1; /* socket side: client- or server-side       */
    unsigned/*bool*/    keep:1; /* whether to keep OS handle upon close      */
    unsigned       crossexec:1; /* =1 if close-on-exec must NOT be set       */
    unsigned       connected:1; /* =1 if remote end-point is fully connected */
    unsigned        r_tv_set:1; /* =1 if read  timeout is set (i.e. finite)  */
    unsigned        w_tv_set:1; /* =1 if write timeout is set (i.e. finite)  */
    unsigned        c_tv_set:1; /* =1 if close timeout is set (i.e. finite)  */
    unsigned       keepalive:1; /* =1 if needs to be kept alive (if OS supp.)*/
#ifndef NCBI_OS_MSWIN
    unsigned        reserved:8; /* MBZ                                       */
#else
    unsigned        reserved:5; /* MBZ                                       */
    unsigned        readable:1; /* =1 if known to be readable                */
    unsigned        writable:1; /* =1 if known to be writeable               */
    unsigned         closing:1; /* =1 if FD_CLOSE posted                     */

    WSAEVENT         event;     /* event bound to I/O                        */
#endif /*!NCBI_OS_MSWIN*/

    void*            session;   /* secure session id if secure, else 0       */

    /* timeouts */
    struct timeval   r_tv;      /* finite read  timeout value                */
    struct timeval   w_tv;      /* finite write timeout value                */
    struct timeval   c_tv;      /* finite close timeout value                */
    STimeout         r_to;      /* finite read  timeout value (aux., temp.)  */
    STimeout         w_to;      /* finite write timeout value (aux., temp.)  */
    STimeout         c_to;      /* finite close timeout value (aux., temp.)  */

    /* aux I/O data */
    BUF              r_buf;     /* read  buffer                              */
    BUF              w_buf;     /* write buffer                              */
    size_t           r_len;     /* DSOCK: size of last message received      */
    size_t           w_len;     /* SOCK: how much data is pending for output */

    /* statistics */
    TNCBI_BigCount   n_read;    /* DSOCK: total # of bytes read (in all msgs)
                                   SOCK:  # of bytes read since last connect
                                */
    TNCBI_BigCount   n_written; /* DSOCK: total # of bytes written (all msgs)
                                   SOCK:  # of bytes written since last connect
                                */
    TNCBI_BigCount   n_in;      /* DSOCK: total # of messages received
                                   SOCK:  total # of bytes read in all
                                   completed connections in this SOCK so far
                                */
    TNCBI_BigCount   n_out;     /* DSOCK: total # of messages sent
                                   SOCK:  total # of bytes written in all
                                   completed connections in this SOCK so far
                                */
#ifdef NCBI_OS_UNIX
    /* pathname for UNIX socket */
    char             path[1];   /* must go last                              */
#endif /*NCBI_OS_UNIX*/
} SOCK_struct;


/*
 * The following implementation details are worth noting:
 *
 * 1. w_buf is used for stream sockets to keep initial data segment
 *    that has to be sent upon connection establishment.
 *
 * 2. eof is used differently for stream and datagram sockets:
 *    =1 for stream sockets means that read has hit EOF;
 *    =1 for datagram sockets means that message in w_buf has been completed.
 *
 * 3. r_status keeps completion code of the last low-level read call;
 *    however, eIO_Closed is there when the socket is shut down for reading;
 *    see the table below for full details on stream sockets.
 *
 * 4. w_status keeps completion code of the last low-level write call;
 *    however, eIO_Closed is there when the socket is shut down for writing.
 *
 * 5. The following table depicts r_status and eof combinations and their
 *    meanings for stream sockets:
 * -------------------------------+--------------------------------------------
 *              Field             |
 * ---------------+---------------+                  Meaning
 * sock->r_status |   sock->eof   |           (stream sockets only)
 * ---------------+---------------+--------------------------------------------
 * eIO_Closed     |       0       |  Socket shut down for reading
 * eIO_Closed     |       1       |  Read severely failed
 * not eIO_Closed |       0       |  Read completed with r_status error
 * not eIO_Closed |       1       |  Read hit EOF (and [maybe later] r_status)
 * ---------------+---------------+--------------------------------------------
 */


#if defined(NCBI_OS_MSWIN)  &&  defined(_WIN64)
#  pragma pack(pop)
#endif /*NCBI_OS_MSWIN && _WIN64*/


extern const char g_kNcbiSockNameAbbr[];


#ifdef __cplusplus
} /* extern "C" */
#endif /*__cplusplus*/


#endif /* CONNECT___NCBI_SOCKETP__H */