From 1c2e0e6a3d1269bea8915192816efefe3dacd8aa Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Wed, 20 Nov 2002 23:15:32 +0000 Subject: [PATCH] General code clean-up and documentation for socket functions. --- src/common/slurm_protocol_api.c | 16 +- src/common/slurm_protocol_interface.h | 155 +++++++++++++++--- src/common/slurm_protocol_socket_common.h | 35 +++- .../slurm_protocol_socket_implementation.c | 51 +----- 4 files changed, 179 insertions(+), 78 deletions(-) diff --git a/src/common/slurm_protocol_api.c b/src/common/slurm_protocol_api.c index e81ee1e336f..f01744b759e 100644 --- a/src/common/slurm_protocol_api.c +++ b/src/common/slurm_protocol_api.c @@ -314,8 +314,7 @@ int slurm_receive_msg(slurm_fd open_fd, slurm_msg_t * msg) buftemp = xmalloc(SLURM_PROTOCOL_MAX_MESSAGE_BUFFER_SIZE); if ((rc = _slurm_msg_recvfrom(open_fd, buftemp, SLURM_PROTOCOL_MAX_MESSAGE_BUFFER_SIZE, - SLURM_PROTOCOL_NO_SEND_RECV_FLAGS, - &(msg)->address)) + SLURM_PROTOCOL_NO_SEND_RECV_FLAGS)) == SLURM_SOCKET_ERROR) { xfree(buftemp); return rc; @@ -446,8 +445,8 @@ int slurm_send_node_msg(slurm_fd open_fd, slurm_msg_t * msg) #endif if ((rc = _slurm_msg_sendto(open_fd, get_buf_data(buffer), get_buf_offset(buffer), - SLURM_PROTOCOL_NO_SEND_RECV_FLAGS, - &msg->address)) == SLURM_SOCKET_ERROR) + SLURM_PROTOCOL_NO_SEND_RECV_FLAGS )) + == SLURM_SOCKET_ERROR) error("Error sending msg socket: %m"); free_buf(buffer); @@ -594,14 +593,14 @@ void slurm_set_addr_any(slurm_addr * slurm_address, uint16_t port) } /* slurm_set_addr - * initializes the slurm_address with the supplied port and ip_address + * initializes the slurm_address with the supplied port and host name * OUT slurm_address - slurm_addr to be filled in * IN port - port in host order * IN host - hostname or dns name */ void slurm_set_addr(slurm_addr * slurm_address, uint16_t port, char *host) { - _slurm_set_addr(slurm_address, port, host); + _slurm_set_addr_char(slurm_address, port, host); } /* reset_slurm_addr @@ -627,7 +626,7 @@ void slurm_set_addr_char(slurm_addr * slurm_address, uint16_t port, } /* slurm_get_addr - * given a slurm_address it returns to port and hostname + * given a slurm_address it returns its port and hostname * IN slurm_address - slurm_addr to be queried * OUT port - port number * OUT host - hostname @@ -661,7 +660,8 @@ int slurm_get_peer_addr(slurm_fd fd, slurm_addr * slurm_address) * IN address - slurm_addr to print * IN buf - space for string representation of slurm_addr * IN n - max number of bytes to write (including NUL) - */void slurm_print_slurm_addr(slurm_addr * address, char *buf, size_t n) + */ +void slurm_print_slurm_addr(slurm_addr * address, char *buf, size_t n) { _slurm_print_slurm_addr(address, buf, n); } diff --git a/src/common/slurm_protocol_interface.h b/src/common/slurm_protocol_interface.h index 074e028e56b..1e4a6539ab8 100644 --- a/src/common/slurm_protocol_interface.h +++ b/src/common/slurm_protocol_interface.h @@ -28,7 +28,7 @@ #define _SLURM_PROTOCOL_INTERFACE_H #if HAVE_CONFIG_H -# include <config.h> +# include "config.h" # if HAVE_INTTYPES_H # include <inttypes.h> # else @@ -61,8 +61,8 @@ #include <fcntl.h> #include <stdarg.h> -#include <src/common/pack.h> -#include <src/common/slurm_protocol_common.h> +#include "src/common/pack.h" +#include "src/common/slurm_protocol_common.h" #define SLURM_MESSGE_TIMEOUT_MSEC_STATIC 10000 @@ -78,6 +78,7 @@ typedef enum slurm_socket_type { /*******************************\ ** MIDDLE LAYER FUNCTIONS ** \*******************************/ + /* The must have funtions are required to implement a low level plugin * for the slurm protocol the general purpose functions just wrap * standard socket calls, so if the underlying layer implements a @@ -90,40 +91,131 @@ typedef enum slurm_socket_type { /*****************************/ /* socket creation functions */ /*****************************/ + +/* Create a socket of the specified type + * IN type - SLURM_STREAM or SLURM_MESSAGE + */ slurm_fd _slurm_create_socket (slurm_socket_type_t type) ; /*****************/ /* msg functions */ /*****************/ + +/* _slurm_init_msg_engine + * In the socket implementation it creates a socket, binds to it, and + * listens for connections. + * IN slurm_address - address to bind to + * RET file descriptor + */ slurm_fd _slurm_init_msg_engine ( slurm_addr * slurm_address ) ; + +/* _slurm_open_msg_conn + * In the bsd socket implementation it creates a SOCK_STREAM socket + * and calls connect on it a SOCK_DGRAM socket called with connect + * is defined to only receive messages from the address/port pair + * argument of the connect call slurm_address - for now it is + * really just a sockaddr_in + * IN slurm_address - address to bind to + * RET file descriptor + */ + slurm_fd _slurm_open_msg_conn ( slurm_addr * slurm_address ) ; + +/* _slurm_msg_recvfrom + * Get message over the given connection, default timeout value + * IN open_fd - an open file descriptor + * OUT buffer - loaded with data + * IN size - size of buffer in bytes + * IN flags - communication specific flags + * RET number of bytes read + */ ssize_t _slurm_msg_recvfrom ( slurm_fd open_fd, char *buffer , - size_t size , - uint32_t flags, slurm_addr * slurm_address ) ; + size_t size , uint32_t flags ) ; +/* _slurm_msg_recvfrom_timeout is identical to _slurm_msg_recvfrom except + * IN timeout - maximum time to wait for a message in milliseconds */ ssize_t _slurm_msg_recvfrom_timeout ( slurm_fd open_fd, char *buffer , - size_t size , uint32_t flags, - slurm_addr * slurm_address , int timeout) ; + size_t size , uint32_t flags, int timeout) ; + +/* _slurm_msg_sendto + * Send message over the given connection, default timeout value + * IN open_fd - an open file descriptor + * IN buffer - data to transmit + * IN size - size of buffer in bytes + * IN flags - communication specific flags + * RET number of bytes written + */ ssize_t _slurm_msg_sendto ( slurm_fd open_fd, char *buffer , - size_t size , uint32_t flags, - slurm_addr * slurm_address ) ; + size_t size , uint32_t flags ) ; +/* _slurm_msg_sendto_timeout is identical to _slurm_msg_sendto except + * IN timeout - maximum time to wait for a message in milliseconds */ ssize_t _slurm_msg_sendto_timeout ( slurm_fd open_fd, char *buffer , - size_t size , uint32_t flags, - slurm_addr * slurm_address , int timeout ) ; + size_t size , uint32_t flags, int timeout ) ; + +/* _slurm_accept_msg_conn + * In the bsd implmentation maps directly to a accept call + * IN open_fd - file descriptor to accept connection on + * OUT slurm_address - slurm_addr of the accepted connection + * RET slurm_fd - file descriptor of the connection created + */ slurm_fd _slurm_accept_msg_conn ( slurm_fd open_fd , slurm_addr * slurm_address ) ; + + +/* _slurm_close_accepted_conn + * In the bsd implmentation maps directly to a close call, to close + * the socket that was accepted + * IN open_fd - an open file descriptor to close + * RET int - the return code + */ int _slurm_close_accepted_conn ( slurm_fd open_fd ) ; /********************/ /* stream functions */ /********************/ + +/* _slurm_listen_stream + * opens a stream server and listens on it + * IN slurm_address - slurm_addr to bind the server stream to + * RET slurm_fd - file descriptor of the stream created + */ slurm_fd _slurm_listen_stream ( slurm_addr * slurm_address ) ; + +/* _slurm_accept_stream + * accepts a incomming stream connection on a stream server slurm_fd + * IN open_fd - file descriptor to accept connection on + * OUT slurm_address - slurm_addr of the accepted connection + * RET slurm_fd - file descriptor of the accepted connection + */ slurm_fd _slurm_accept_stream ( slurm_fd open_fd , slurm_addr * slurm_address ) ; + +/* _slurm_open_stream + * opens a client connection to stream server + * IN slurm_address - slurm_addr of the connection destination + * RET slurm_fd - file descriptor of the connection created + */ slurm_fd _slurm_open_stream ( slurm_addr * slurm_address ) ; + +/* _slurm_get_stream_addr + * esentially a encapsilated get_sockname + * IN open_fd - file descriptor to retreive slurm_addr for + * OUT address - address that open_fd to bound to + */ extern int _slurm_get_stream_addr ( slurm_fd open_fd , slurm_addr * address ) ; + +/* _slurm_close_stream + * closes either a server or client stream file_descriptor + * IN open_fd - an open file descriptor to close + * RET int - the return code + */ extern int _slurm_close_stream ( slurm_fd open_fd ) ; +/* make an open slurm connection blocking or non-blocking + * (i.e. wait or do not wait for i/o completion ) + * IN open_fd - an open file descriptor to change the effect + * RET int - the return code + */ extern inline int _slurm_set_stream_non_blocking ( slurm_fd open_fd ) ; extern inline int _slurm_set_stream_blocking ( slurm_fd open_fd ) ; @@ -135,17 +227,42 @@ int _slurm_recv_timeout ( slurm_fd open_fd, char *buffer , /***************************/ /* slurm address functions */ /***************************/ +/* build a slurm address bassed upon ip address and port number + * OUT slurm_address - the constructed slurm_address + * IN port - port to be used + * IN ip_address - the IP address to connect with + */ extern void _slurm_set_addr_uint ( slurm_addr * slurm_address , uint16_t port , uint32_t ip_address ) ; + +/* resets the address field of a slurm_addr, port and family are unchanged */ extern void _reset_slurm_addr ( slurm_addr * slurm_address , slurm_addr new_address ); -extern void _slurm_set_addr ( slurm_addr * slurm_address , - uint16_t port , char * host ) ; + + +/* build a slurm address bassed upon host name and port number + * OUT slurm_address - the constructed slurm_address + * IN port - port to be used + * IN host - name of host to connect with + */ extern void _slurm_set_addr_char ( slurm_addr * slurm_address , uint16_t port , char * host ) ; + +/* given a slurm_address it returns its port and hostname + * IN slurm_address - slurm_addr to be queried + * OUT port - port number + * OUT host - hostname + * IN buf_len - length of hostname buffer + */ extern void _slurm_get_addr ( slurm_addr * slurm_address , uint16_t * port , char * host , uint32_t buf_len ) ; + +/* prints a slurm_addr into a buf + * IN address - slurm_addr to print + * IN buf - space for string representation of slurm_addr + * IN n - max number of bytes to write (including NUL) + */ extern void _slurm_print_slurm_addr ( slurm_addr * address, char *buf, size_t n ) ; @@ -263,18 +380,6 @@ extern int _slurm_setsockopt (int __fd, int __level, int __optname, 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, ... ); extern int _slurm_vfcntl(int fd, int cmd, va_list va ); diff --git a/src/common/slurm_protocol_socket_common.h b/src/common/slurm_protocol_socket_common.h index b07c9c8cef8..2e8534da5ea 100644 --- a/src/common/slurm_protocol_socket_common.h +++ b/src/common/slurm_protocol_socket_common.h @@ -1,8 +1,35 @@ +/*****************************************************************************\ + * slurm_protocol_socket_common.h - slurm communications interface + * definitions based upon sockets + ***************************************************************************** + * Copyright (C) 2002 The Regents of the University of California. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * Written by Kevin Tew <tew1@llnl.gov>, et. al. + * UCRL-CODE-2002-040. + * + * This file is part of SLURM, a resource management program. + * For details, see <http://www.llnl.gov/linux/slurm/>. + * + * SLURM is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with SLURM; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\*****************************************************************************/ + #ifndef _SLURM_PROTOCOL_SOCKET_COMMON_H #define _SLURM_PROTOCOL_SOCKET_COMMON_H #if HAVE_CONFIG_H -# include <config.h> +# include "config.h" # if HAVE_INTTYPES_H # include <inttypes.h> # else @@ -20,7 +47,8 @@ #define SLURM_INADDR_ANY 0x00000000 /* LINUX SPECIFIC */ -/* this is the slurm equivalent of the operating system file descriptor, which in linux is just an int */ +/* this is the slurm equivalent of the operating system file descriptor, + * which in linux is just an int */ typedef int32_t slurm_fd ; /* this is the slurm equivalent of the BSD sockets sockaddr @@ -37,7 +65,8 @@ typedef fd_set _slurm_fd_set ; int16_t family ; uint16_t port ; uint32_t address ; - char pad[16 - sizeof ( int16_t ) - sizeof (uint16_t) - sizeof (uint32_t) ] ; + char pad[16 - sizeof ( int16_t ) - sizeof (uint16_t) - + sizeof (uint32_t) ] ; } ; */ diff --git a/src/common/slurm_protocol_socket_implementation.c b/src/common/slurm_protocol_socket_implementation.c index 75279e2b8e0..cb7f0883ac8 100644 --- a/src/common/slurm_protocol_socket_implementation.c +++ b/src/common/slurm_protocol_socket_implementation.c @@ -25,6 +25,10 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. \*****************************************************************************/ +#if HAVE_CONFIG_H +# include "config.h" +#endif + #include <unistd.h> #include <string.h> #include <netdb.h> @@ -47,15 +51,12 @@ #endif #include "src/common/slurm_protocol_interface.h" -#include "src/common/slurm_protocol_common.h" #include "src/common/slurm_protocol_defs.h" #include "src/common/log.h" -#include "src/common/pack.h" #include "src/common/util-net.h" #define TEMP_BUFFER_SIZE 1024 - /* internal static prototypes */ /***************************************************************** * MIDDLE LAYER MSG FUNCTIONS @@ -72,7 +73,8 @@ slurm_fd _slurm_open_msg_conn ( 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) +slurm_fd _slurm_accept_msg_conn (slurm_fd open_fd , + slurm_addr * slurm_address) { return _slurm_accept_stream ( open_fd , slurm_address ) ; } @@ -83,16 +85,14 @@ int _slurm_close_accepted_conn ( slurm_fd open_fd ) } ssize_t _slurm_msg_recvfrom ( slurm_fd open_fd, char *buffer , size_t size , - uint32_t flags, slurm_addr * slurm_address ) + uint32_t flags ) { return _slurm_msg_recvfrom_timeout ( open_fd , buffer , size , flags , - slurm_address , SLURM_MESSGE_TIMEOUT_MSEC_STATIC ) ; } ssize_t _slurm_msg_recvfrom_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, - slurm_addr * slurm_address , int timeout) { size_t recv_len ; @@ -235,16 +235,14 @@ ssize_t _slurm_msg_recvfrom_timeout ( slurm_fd open_fd, char *buffer , } ssize_t _slurm_msg_sendto ( slurm_fd open_fd, char *buffer , size_t size , - uint32_t flags, slurm_addr * slurm_address ) + uint32_t flags ) { return _slurm_msg_sendto_timeout ( open_fd, buffer , size , flags, - slurm_address , SLURM_MESSGE_TIMEOUT_MSEC_STATIC ) ; } ssize_t _slurm_msg_sendto_timeout ( slurm_fd open_fd, char *buffer , - size_t size , uint32_t flags, - slurm_addr * slurm_address , int timeout ) + size_t size , uint32_t flags , int timeout ) { size_t send_len ; @@ -746,32 +744,6 @@ extern int _slurm_close (int __fd ) return close ( __fd ) ; } -extern int _slurm_select(int n, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, struct timeval *timeout) -{ - assert (n <= FD_SETSIZE); /* select data structure overflows */; - return select ( n , readfds , writefds , exceptfds , timeout ) ; -} -extern void _slurm_FD_CLR(int fd, fd_set *set) -{ - assert (fd < FD_SETSIZE); /* select data structure overflows */; - FD_CLR ( fd , set ) ; -} -extern int _slurm_FD_ISSET(int fd, fd_set *set) -{ - assert (fd < FD_SETSIZE); /* select data structure overflows */; - return FD_ISSET ( fd , set ) ; -} -extern void _slurm_FD_SET(int fd, fd_set *set) -{ - assert (fd < FD_SETSIZE); /* select data structure overflows */; - FD_SET ( fd , set ) ; -} -extern void _slurm_FD_ZERO(fd_set *set) -{ - FD_ZERO ( set ) ; -} - extern int _slurm_fcntl(int fd, int cmd, ... ) { int rc ; @@ -817,11 +789,6 @@ void _reset_slurm_addr ( slurm_addr * slurm_address , slurm_addr new_address ) slurm_address -> sin_addr.s_addr = new_address.sin_addr.s_addr ; } -/* sets the fields of a slurm_addr */ -void _slurm_set_addr ( slurm_addr * slurm_address , uint16_t port , char * host ) -{ - _slurm_set_addr_char ( slurm_address , port , host ) ; -} void _slurm_set_addr_char ( slurm_addr * slurm_address , uint16_t port , char * host ) { -- GitLab