1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4
* (C) 2001 by Argonne National Laboratory.
5
* See COPYRIGHT in top-level directory.
8
#include "smpd_util_sock.h"
9
/*#include "mpiimpl.h"*/
11
/* Include for memcpy and memset */
15
#include "mpishared.h"
18
#include <sys/types.h>
19
#include <sys/socket.h>
21
#include <netinet/tcp.h>
22
#include <netinet/in.h>
24
#if defined(HAVE_POLL_H)
26
#elif defined(HAVE_SYS_POLL_H)
35
/* FIXME: What do these mean? Why is 32 a good size (e.g., is it because
36
32*32 = 1024 if these are bits in a 4-byte int? In that case, should
37
these be related to a maximum processor count or an OS-defined fd limit? */
38
#if !defined(SMPDU_SOCK_SET_DEFAULT_SIZE)
39
#define SMPDU_SOCK_SET_DEFAULT_SIZE 32
42
#if !defined(SMPDU_SOCK_EVENTQ_POOL_SIZE)
43
#define SMPDU_SOCK_EVENTQ_POOL_SIZE 32
47
enum SMPDU_Socki_state
49
SMPDU_SOCKI_STATE_FIRST = 0,
50
SMPDU_SOCKI_STATE_CONNECTING,
51
SMPDU_SOCKI_STATE_CONNECTED_RW,
52
SMPDU_SOCKI_STATE_CONNECTED_RO,
53
SMPDU_SOCKI_STATE_DISCONNECTED,
54
SMPDU_SOCKI_STATE_CLOSING,
55
SMPDU_SOCKI_STATE_LAST
60
SMPDU_SOCKI_TYPE_FIRST = 0,
61
SMPDU_SOCKI_TYPE_COMMUNICATION,
62
SMPDU_SOCKI_TYPE_LISTENER,
63
SMPDU_SOCKI_TYPE_INTERRUPTER,
70
* sock_id - an integer id comprised of the sock_set id and the element number
71
* in the pollfd/info arrays
73
* sock_set - a pointer to the sock set to which this connection belongs
75
* elem - the element number of this connection in the pollfd/info arrays
77
* sock - at present this is only used to free the sock structure when the
78
* close is completed by SMPDIU_Sock_wait()
80
* fd - this file descriptor is used whenever the file descriptor is needed.
81
* this descriptor remains open until the sock, and
82
* thus the socket, are actually closed. the fd in the pollfd structure
83
* should only be used for telling poll() if it should
84
* check for events on that descriptor.
86
* user_ptr - a user supplied pointer that is included with event associated
87
* with this connection
89
* state - state of the connection
95
struct SMPDU_Sock_set * sock_set;
97
struct SMPDU_Sock * sock;
100
enum SMPDU_Socki_type type;
101
enum SMPDU_Socki_state state;
114
SMPDU_Sock_size_t min;
115
SMPDU_Sock_size_t max;
119
SMPDU_Sock_size_t read_nb;
120
SMPDU_Sock_progress_update_func_t read_progress_update_fn;
132
SMPDU_Sock_size_t min;
133
SMPDU_Sock_size_t max;
137
SMPDU_Sock_size_t write_nb;
138
SMPDU_Sock_progress_update_func_t write_progress_update_fn;
141
struct SMPDU_Socki_eventq_elem
143
struct SMPDU_Sock_event event;
145
struct SMPDU_Socki_eventq_elem * next;
148
struct SMPDU_Sock_set
152
/* when the pollfds array is scanned for activity, start with this element.
153
this is used to prevent favoring a particular
154
element, such as the first. */
157
/* pointers to the pollfd and pollinfo that make up the logical poll array,
158
along with the current size of the array and last
161
int poll_array_elems;
162
struct pollfd * pollfds;
163
struct pollinfo * pollinfos;
165
/* head and tail pointers for the event queue */
166
struct SMPDU_Socki_eventq_elem * eventq_head;
167
struct SMPDU_Socki_eventq_elem * eventq_tail;
172
struct SMPDU_Sock_set * sock_set;
176
/* FIXME: Why aren't these static */
177
int SMPDU_Socki_initialized = 0;
179
static struct SMPDU_Socki_eventq_elem * SMPDU_Socki_eventq_pool = NULL;
181
/* MT: needs to be atomically incremented */
182
static int SMPDU_Socki_set_next_id = 0;
184
/* Prototypes for functions used only within the socket code. */
186
/* Set the buffer size on the socket fd from the environment variable
187
or other option; if "firm" is true, fail if the buffer size is not
189
int SMPDU_Sock_SetSockBufferSize( int fd, int firm );
190
/* Get a string version of the address in ifaddr*/
191
int SMPDU_Sock_AddrToStr( SMPDU_Sock_ifaddr_t *ifaddr, char *str, int maxlen );
193
/* FIXME: Why are these files included in this way? Why not make them either
194
separate files or simply part of (one admittedly large) source file? */
195
#include "smpd_socki_util.i"
197
#include "smpd_sock_init.i"
198
#include "smpd_sock_set.i"
199
#include "smpd_sock_post.i"
200
#include "smpd_sock_immed.i"
201
#include "smpd_sock_misc.i"
202
#include "smpd_sock_wait.i"