diff --git a/src/common/slurm_protocol_api.c b/src/common/slurm_protocol_api.c index a2bb2231339399b82db651a74604629154f2fbb8..55c617a9e74ba36d201158b49bf42da09277e72a 100644 --- a/src/common/slurm_protocol_api.c +++ b/src/common/slurm_protocol_api.c @@ -524,6 +524,33 @@ int slurm_close_stream ( slurm_fd open_fd ) return _slurm_close_stream ( open_fd ) ; } +int slurm_select(int n, slurm_fd_set *readfds, slurm_fd_set *writefds, slurm_fd_set *exceptfds, struct timeval *timeout) +{ + return _slurm_select(n, readfds, writefds, exceptfds, timeout); +} + +void slurm_FD_CLR(slurm_fd fd, slurm_fd_set *set) +{ + return _slurm_FD_CLR(fd, set); +} + +int slurm_FD_ISSET(slurm_fd fd, slurm_fd_set *set) +{ + return _slurm_FD_ISSET(fd, set); +} + +void slurm_FD_SET(slurm_fd fd, slurm_fd_set *set) +{ + return _slurm_FD_SET(fd, set); +} + +void slurm_FD_ZERO(slurm_fd_set *set) +{ + return _slurm_FD_ZERO(set); +} + + + /************************/ /***** slurm addr functions */ /************************/ diff --git a/src/common/slurm_protocol_api.h b/src/common/slurm_protocol_api.h index b9a806a36697a379bb843bf7b687c14327749dc1..c728d88569395f4b3ec3117f78f821dcf1240e8e 100644 --- a/src/common/slurm_protocol_api.h +++ b/src/common/slurm_protocol_api.h @@ -146,7 +146,7 @@ int slurm_send_controller_msg ( slurm_fd open_fd , slurm_msg_t * msg ) ; int slurm_send_node_msg ( slurm_fd open_fd , slurm_msg_t * msg ) ; /**********************************************************************/ -/* connection establishment functions used by msg clients */ +/* msg connection establishment functions used by msg clients */ /**********************************************************************/ /* calls connect to make a connection-less datagram connection to the the primary or secondary slurmctld message engine @@ -229,6 +229,11 @@ size_t inline slurm_read_stream ( slurm_fd open_fd , char * buffer , size_t size */ int inline slurm_get_stream_addr ( slurm_fd open_fd , slurm_addr * address ) ; +int inline slurm_select(int n, slurm_fd_set *readfds, slurm_fd_set *writefds, slurm_fd_set *exceptfds, struct timeval *timeout) ; +void inline slurm_FD_CLR(slurm_fd, slurm_fd_set *set) ; +int inline slurm_FD_ISSET(slurm_fd, slurm_fd_set *set) ; +void inline slurm_FD_SET(slurm_fd, slurm_fd_set *set) ; +void inline slurm_FD_ZERO(slurm_fd_set *set) ; /**********************************************************************/ /* raw msg buffer send functions */ diff --git a/src/common/slurm_protocol_interface.h b/src/common/slurm_protocol_interface.h index 45b8cc81d25fa7749ce9b5132120c42ea61e008a..506accf71b1b541daedfbbeadeb25c961a1e75f7 100644 --- a/src/common/slurm_protocol_interface.h +++ b/src/common/slurm_protocol_interface.h @@ -47,53 +47,66 @@ ** Data Types ** \****************/ - +typedef enum slurm_socket_type { SLURM_MESSAGE , SLURM_STREAM } slurm_socket_type_t; /*******************************\ - ** Must Have Functions ** + ** MIDDLE LAYER FUNCTIONS ** \*******************************/ /* The must have funtions are required to implement a low level plugin for the slurm protocol - * the genereal purpose functions just wrap standard socket calls, so if the underlying layer + * the general purpose functions just wrap standard socket calls, so if the underlying layer * implements a socket like interface, it can be used as a low level transport plugin with slurm - * * the _slurm_recv and _slurm_send functions are also needed */ -typedef enum slurm_socket_type { SLURM_MESSAGE , SLURM_STREAM } slurm_socket_type_t; - -/* high level interface */ +/*****************************/ +/* socket creation functions */ +/*****************************/ slurm_fd _slurm_create_socket (slurm_socket_type_t type) ; + +/*****************/ /* msg functions */ +/*****************/ slurm_fd _slurm_init_msg_engine ( slurm_addr * slurm_address ) ; slurm_fd _slurm_open_msg_conn ( slurm_addr * slurm_address ) ; ssize_t _slurm_msg_recvfrom ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, slurm_addr * slurm_address ) ; ssize_t _slurm_msg_sendto ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, slurm_addr * slurm_address ) ; -/* this should be a no-op that just returns open_fd in a message implementation */ slurm_fd _slurm_accept_msg_conn ( slurm_fd open_fd , slurm_addr * slurm_address ) ; -/* this should be a no-op in a message implementation */ int _slurm_close_accepted_conn ( slurm_fd open_fd ) ; - - +/********************/ /* stream functions */ +/********************/ slurm_fd _slurm_listen_stream ( slurm_addr * slurm_address ) ; slurm_fd _slurm_accept_stream ( slurm_fd open_fd , slurm_addr * slurm_address ) ; slurm_fd _slurm_open_stream ( slurm_addr * slurm_address ) ; extern int _slurm_get_stream_addr ( slurm_fd open_fd , slurm_addr * address ) ; extern int _slurm_close_stream ( slurm_fd open_fd ) ; +/***************************/ +/* slurm address functions */ +/***************************/ +extern void _slurm_set_addr_uint ( slurm_addr * slurm_address , uint16_t port , uint32_t ip_address ) ; +extern void _slurm_set_addr ( slurm_addr * slurm_address , uint16_t port , char * host ) ; +extern void _slurm_set_addr_char ( slurm_addr * slurm_address , uint16_t port , char * host ) ; +extern void _slurm_get_addr ( slurm_addr * slurm_address , uint16_t * port , char * host , uint32_t buf_len ) ; + +/*****************************/ +/* slurm addr pack functions */ +/*****************************/ +extern void _slurm_pack_slurm_addr ( slurm_addr * slurm_address , void ** buffer , int * length ) ; +extern void _slurm_unpack_slurm_addr_no_alloc ( slurm_addr * slurm_address , void ** buffer , int * length ) ; + + /*******************************\ - ** General-Purpose Functions ** + ** BSD LINUX SOCKET FUNCTIONS ** \*******************************/ /* Create a new socket of type TYPE in domain DOMAIN, using - * protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically. - * Returns a file descriptor for the new socket, or -1 for errors. */ + * protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically. + * Returns a file descriptor for the new socket, or -1 for errors. */ extern int _slurm_socket (int __domain, int __type, int __protocol) ; - - /* Create two new sockets, of type TYPE in domain DOMAIN and using * protocol PROTOCOL, which are connected to each other, and put file * descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero, @@ -102,9 +115,6 @@ extern int _slurm_socketpair (int __domain, int __type, int __protocol, int __fd /* Give the socket FD the local address ADDR (which is LEN bytes long). */ extern int _slurm_bind (int __fd, struct sockaddr const * __addr, socklen_t __len) ; - -/* Put the local address of FD into *ADDR and its length in *LEN. */ -extern int _slurm_getsockname (int __fd, struct sockaddr * __addr, socklen_t *__restrict __len) ; /* Open a connection on socket FD to peer at ADDR (which LEN bytes long). * For connectionless socket types, just set the default address to send to @@ -112,6 +122,21 @@ extern int _slurm_getsockname (int __fd, struct sockaddr * __addr, socklen_t *__ * Return 0 on success, -1 for errors. */ extern int _slurm_connect (int __fd, struct sockaddr const * __addr, socklen_t __len) ; +/* Prepare to accept connections on socket FD. + * N connection requests will be queued before further requests are refused. + * Returns 0 on success, -1 for errors. */ +extern int _slurm_listen (int __fd, int __n) ; + +/* Await a connection on socket FD. + * When a connection arrives, open a new socket to communicate with it, + * set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting + * peer and *ADDR_LEN to the address's actual length, and return the + * new socket's descriptor, or -1 for errors. */ +extern int _slurm_accept (int __fd, struct sockaddr * __addr, socklen_t *__restrict __addr_len) ; + +/* Put the local address of FD into *ADDR and its length in *LEN. */ +extern int _slurm_getsockname (int __fd, struct sockaddr * __addr, socklen_t *__restrict __len) ; + /* Put the address of the peer connected to socket FD into *ADDR * (which is *LEN bytes long), and its actual length into *LEN. */ extern int _slurm_getpeername (int __fd, struct sockaddr * __addr, socklen_t *__restrict __len) ; @@ -129,16 +154,16 @@ extern ssize_t _slurm_read (int __fd, void *__buf, size_t __n) ; * ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */ extern ssize_t _slurm_sendto (int __fd, __const void *__buf, size_t __n, int __flags, struct sockaddr const * __addr, socklen_t __addr_len) ; +/* Send a msg described MESSAGE on socket FD. + * Returns the number of bytes sent, or -1 for errors. */ +extern ssize_t _slurm_sendmsg (int __fd, __const struct msghdr *__msg, int __flags) ; + /* Read N bytes into BUF through socket FD. * If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of * the sender, and store the actual size of the address in *ADDR_LEN. * Returns the number of bytes read or -1 for errors. */ extern ssize_t _slurm_recvfrom (int __fd, void *__restrict __buf, size_t __n, int __flags, struct sockaddr * __addr, socklen_t *__restrict __addr_len) ; -/* Send a msg described MESSAGE on socket FD. - * Returns the number of bytes sent, or -1 for errors. */ -extern ssize_t _slurm_sendmsg (int __fd, __const struct msghdr *__msg, int __flags) ; - /* Send a msg described MESSAGE on socket FD. * Returns the number of bytes read or -1 for errors. */ extern ssize_t _slurm_recvmsg (int __fd, struct msghdr *__msg, int __flags) ; @@ -153,18 +178,6 @@ extern int _slurm_getsockopt (int __fd, int __level, int __optname, void *__rest * Returns 0 on success, -1 for errors. */ extern int _slurm_setsockopt (int __fd, int __level, int __optname, __const void *__optval, socklen_t __optlen) ; -/* Prepare to accept connections on socket FD. - * N connection requests will be queued before further requests are refused. - * Returns 0 on success, -1 for errors. */ -extern int _slurm_listen (int __fd, int __n) ; - -/* Await a connection on socket FD. - * When a connection arrives, open a new socket to communicate with it, - * set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting - * peer and *ADDR_LEN to the address's actual length, and return the - * new socket's descriptor, or -1 for errors. */ -extern int _slurm_accept (int __fd, struct sockaddr * __addr, socklen_t *__restrict __addr_len) ; - /* Shut down all or part of the connection open on socket FD. * HOW determines what to shut down: * SHUT_RD = No more receptions; @@ -174,29 +187,19 @@ extern int _slurm_accept (int __fd, struct sockaddr * __addr, socklen_t *__restr extern int _slurm_shutdown (int __fd, int __how) ; extern int _slurm_close (int __fd ) ; + +/* Non-blocking calls */ extern int _slurm_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); /* extern int _slurm_pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, sigset_t * sigmask); */ - void _slurm_FD_CLR(int fd, fd_set *set); int _slurm_FD_ISSET(int fd, fd_set *set); void _slurm_FD_SET(int fd, fd_set *set); void _slurm_FD_ZERO(fd_set *set); + extern int _slurm_fcntl(int fd, int cmd); /* function overloading problems extern int _slurm_fcntl(int fd, int cmd, long arg); extern int _slurm_fcntl(int fd, int cmd, struct flock *lock); */ - extern int _slurm_ioctl(int d, int request, ...); - -/* sets the fields of a slurm_addr */ -extern void _slurm_set_addr_uint ( slurm_addr * slurm_address , uint16_t port , uint32_t ip_address ) ; -extern void _slurm_set_addr ( slurm_addr * slurm_address , uint16_t port , char * host ) ; -extern void _slurm_set_addr_char ( slurm_addr * slurm_address , uint16_t port , char * host ) ; -extern void _slurm_get_addr ( slurm_addr * slurm_address , uint16_t * port , char * host , uint32_t buf_len ) ; - -/* pack routines for slurm_addr */ -extern void _slurm_pack_slurm_addr ( slurm_addr * slurm_address , void ** buffer , int * length ) ; -extern void _slurm_unpack_slurm_addr_no_alloc ( slurm_addr * slurm_address , void ** buffer , int * length ) ; - #endif /* !_SLURM_PROTOCOL_INTERFACE_H */ diff --git a/src/common/slurm_protocol_mongo_common.h b/src/common/slurm_protocol_mongo_common.h index 0d6d4a3da1c09929cc80e80902d27add73ad1351..51e39f6e9733295643bcc92d4c227ffe58befefd 100644 --- a/src/common/slurm_protocol_mongo_common.h +++ b/src/common/slurm_protocol_mongo_common.h @@ -25,6 +25,8 @@ typedef uint32_t slurm_fd ; /* this is the slurm equivalent of the BSD sockets sockaddr */ typedef struct mongo_addr_t slurm_addr ; +/* this is the slurm equivalent of the BSD sockets fd_set */ +typedef fd_set slurm_fd_set ; /*struct kevin { int16_t family ; uint16_t port ; diff --git a/src/common/slurm_protocol_socket_common.h b/src/common/slurm_protocol_socket_common.h index fe859844ba2db0a28229e1913954f44f6a20f53c..ed1d658cf584ef2aea50bb52ae9433c844c29b13 100644 --- a/src/common/slurm_protocol_socket_common.h +++ b/src/common/slurm_protocol_socket_common.h @@ -25,6 +25,8 @@ typedef uint32_t slurm_fd ; /* this is the slurm equivalent of the BSD sockets sockaddr */ typedef struct sockaddr_in slurm_addr ; +/* this is the slurm equivalent of the BSD sockets fd_set */ +typedef fd_set slurm_fd_set ; /*{ int16_t family ; uint16_t port ;