diff --git a/src/common/slurm_protocol_api.c b/src/common/slurm_protocol_api.c index 3812a6d1d07b24f4a927afe6cf955c0dc11979c2..75ee494fff368ab64ea7a6ffee4cc80c615b4978 100644 --- a/src/common/slurm_protocol_api.c +++ b/src/common/slurm_protocol_api.c @@ -508,7 +508,7 @@ slurm_fd slurm_open_stream(slurm_addr * slurm_address) } size_t slurm_write_stream_timeout_tv(slurm_fd open_fd, char *buffer, - size_t size, struct timeval * timeout) + size_t size, int timeout) { return _slurm_send_timeout(open_fd, buffer, size, SLURM_PROTOCOL_NO_SEND_RECV_FLAGS, @@ -516,7 +516,7 @@ size_t slurm_write_stream_timeout_tv(slurm_fd open_fd, char *buffer, } size_t slurm_read_stream_timeout_tv(slurm_fd open_fd, char *buffer, - size_t size, struct timeval * timeout) + size_t size, int timeout) { return _slurm_recv_timeout(open_fd, buffer, size, SLURM_PROTOCOL_NO_SEND_RECV_FLAGS, @@ -526,41 +526,31 @@ size_t slurm_read_stream_timeout_tv(slurm_fd open_fd, char *buffer, size_t slurm_write_stream_timeout(slurm_fd open_fd, char *buffer, size_t size, int timeout) { - struct timeval time_out; - time_out.tv_sec = timeout; - time_out.tv_usec = 0; return _slurm_send_timeout(open_fd, buffer, size, SLURM_PROTOCOL_NO_SEND_RECV_FLAGS, - &time_out); + timeout); } size_t slurm_read_stream_timeout(slurm_fd open_fd, char *buffer, size_t size, int timeout) { - struct timeval time_out; - time_out.tv_sec = timeout; - time_out.tv_usec = 0; return _slurm_recv_timeout(open_fd, buffer, size, SLURM_PROTOCOL_NO_SEND_RECV_FLAGS, - &time_out); + timeout); } size_t slurm_write_stream(slurm_fd open_fd, char *buffer, size_t size) { - struct timeval SLURM_MESSGE_TIMEOUT_SEC = - SLURM_MESSGE_TIMEOUT_SEC_STATIC; return _slurm_send_timeout(open_fd, buffer, size, SLURM_PROTOCOL_NO_SEND_RECV_FLAGS, - &SLURM_MESSGE_TIMEOUT_SEC); + SLURM_MESSGE_TIMEOUT_MSEC_STATIC); } size_t slurm_read_stream(slurm_fd open_fd, char *buffer, size_t size) { - struct timeval SLURM_MESSGE_TIMEOUT_SEC = - SLURM_MESSGE_TIMEOUT_SEC_STATIC; return _slurm_recv_timeout(open_fd, buffer, size, SLURM_PROTOCOL_NO_SEND_RECV_FLAGS, - &SLURM_MESSGE_TIMEOUT_SEC); + SLURM_MESSGE_TIMEOUT_MSEC_STATIC); } /* diff --git a/src/common/slurm_protocol_interface.h b/src/common/slurm_protocol_interface.h index dde76642013e88db9e27200c22239915e356894c..13636fa3a9490bdeb6ac1d28e1e97169da105e4a 100644 --- a/src/common/slurm_protocol_interface.h +++ b/src/common/slurm_protocol_interface.h @@ -64,7 +64,7 @@ #include <src/common/pack.h> #include <src/common/slurm_protocol_common.h> -extern struct timeval SLURM_MESSGE_TIMEOUT_SEC_STATIC ; +#define SLURM_MESSGE_TIMEOUT_MSEC_STATIC 10000 /****************\ ** Data Types ** @@ -93,9 +93,9 @@ slurm_fd _slurm_create_socket (slurm_socket_type_t type) ; 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_recvfrom_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, slurm_addr * slurm_address , struct timeval * timeout) ; +ssize_t _slurm_msg_recvfrom_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, slurm_addr * slurm_address , int timeout) ; ssize_t _slurm_msg_sendto ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, slurm_addr * slurm_address ) ; -ssize_t _slurm_msg_sendto_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, slurm_addr * slurm_address , struct timeval * timeout ) ; +ssize_t _slurm_msg_sendto_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, slurm_addr * slurm_address , int timeout ) ; slurm_fd _slurm_accept_msg_conn ( slurm_fd open_fd , slurm_addr * slurm_address ) ; int _slurm_close_accepted_conn ( slurm_fd open_fd ) ; @@ -111,8 +111,8 @@ extern int _slurm_close_stream ( slurm_fd open_fd ) ; extern inline int _slurm_set_stream_non_blocking ( slurm_fd open_fd ) ; extern inline int _slurm_set_stream_blocking ( slurm_fd open_fd ) ; -int _slurm_send_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, struct timeval * timeout ) ; -int _slurm_recv_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, struct timeval * timeout ) ; +int _slurm_send_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, int timeout ) ; +int _slurm_recv_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, int timeout ) ; /***************************/ /* slurm address functions */ diff --git a/src/common/slurm_protocol_socket_implementation.c b/src/common/slurm_protocol_socket_implementation.c index bc400200fd543a0d1d62d3e44f27ecbadc4a3dd8..8faa3278967938fde3af75cd737eaf482e59fe02 100644 --- a/src/common/slurm_protocol_socket_implementation.c +++ b/src/common/slurm_protocol_socket_implementation.c @@ -30,6 +30,7 @@ #include <netdb.h> #include <errno.h> #include <netinet/in.h> +#include <sys/poll.h> #include <sys/time.h> #include <sys/types.h> #include <signal.h> @@ -53,9 +54,6 @@ #define TEMP_BUFFER_SIZE 1024 -/* global constants */ -struct timeval SLURM_MESSGE_TIMEOUT_SEC_STATIC = { tv_sec:10L , tv_usec:0 } ; - /* internal static prototypes */ /***************************************************************** @@ -84,11 +82,11 @@ 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 ) { - struct timeval SLURM_MESSGE_TIMEOUT_SEC = SLURM_MESSGE_TIMEOUT_SEC_STATIC ; - return _slurm_msg_recvfrom_timeout ( open_fd , buffer , size , flags , slurm_address , & SLURM_MESSGE_TIMEOUT_SEC ) ; + 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 , struct timeval * timeout) +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 ; @@ -218,11 +216,11 @@ ssize_t _slurm_msg_recvfrom_timeout ( slurm_fd open_fd, char *buffer , size_t si ssize_t _slurm_msg_sendto ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, slurm_addr * slurm_address ) { - struct timeval SLURM_MESSGE_TIMEOUT_SEC = SLURM_MESSGE_TIMEOUT_SEC_STATIC ; - return _slurm_msg_sendto_timeout ( open_fd, buffer , size , flags, slurm_address , & SLURM_MESSGE_TIMEOUT_SEC ) ; + 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 , struct timeval * timeout ) +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 send_len ; @@ -287,30 +285,27 @@ ssize_t _slurm_msg_sendto_timeout ( slurm_fd open_fd, char *buffer , size_t size return SLURM_PROTOCOL_ERROR ; } -int _slurm_send_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, struct timeval * timeout ) +int _slurm_send_timeout ( slurm_fd open_fd, char *buffer , size_t size , + uint32_t flags, int timeout ) { int rc ; int bytes_sent = 0 ; int fd_flags ; - _slurm_fd_set set ; + struct pollfd ufds; - _slurm_FD_ZERO ( & set ) ; + ufds.fd = open_fd; + ufds.events = POLLOUT; fd_flags = _slurm_fcntl ( open_fd , F_GETFL ) ; _slurm_set_stream_non_blocking ( open_fd ) ; while ( bytes_sent < size ) { - _slurm_FD_SET ( open_fd , &set ) ; - rc = _slurm_select ( open_fd + 1 , NULL , & set, NULL , timeout ) ; - if ( (rc == SLURM_PROTOCOL_ERROR) || (rc < 0) ) + rc = poll(&ufds, 1, timeout); + if ( rc < 0 ) { if ( errno == EINTR ) - { continue ; - } else - { goto _slurm_send_timeout_exit_error; - } } else if ( rc == 0 ) @@ -320,17 +315,14 @@ int _slurm_send_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_ } else { - rc = _slurm_send ( open_fd, &buffer[bytes_sent] , (size-bytes_sent) , flags ) ; + rc = _slurm_send ( open_fd, &buffer[bytes_sent] , + (size-bytes_sent) , flags ) ; if ( rc == SLURM_PROTOCOL_ERROR || rc < 0 ) { if ( errno == EINTR ) - { continue ; - } else - { goto _slurm_send_timeout_exit_error; - } } else if ( rc == 0 ) { @@ -339,7 +331,7 @@ int _slurm_send_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_ } else { - bytes_sent+=rc ; + bytes_sent += rc ; } } } @@ -359,31 +351,27 @@ int _slurm_send_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_ } -int _slurm_recv_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_t flags, struct timeval * timeout ) +int _slurm_recv_timeout ( slurm_fd open_fd, char *buffer , size_t size , + uint32_t flags, int timeout ) { int rc ; int bytes_recv = 0 ; int fd_flags ; - _slurm_fd_set set ; - + struct pollfd ufds; - _slurm_FD_ZERO ( & set ) ; + ufds.fd = open_fd; + ufds.events = POLLIN; fd_flags = _slurm_fcntl ( open_fd , F_GETFL ) ; _slurm_set_stream_non_blocking ( open_fd ) ; while ( bytes_recv < size ) { - _slurm_FD_SET ( open_fd , &set ) ; - rc = _slurm_select ( open_fd + 1 , & set , NULL , NULL , timeout ) ; - if ( (rc == SLURM_PROTOCOL_ERROR) || (rc < 0) ) + rc = poll(&ufds, 1, timeout); + if ( rc < 0 ) { if ( errno == EINTR ) - { continue ; - } else - { goto _slurm_recv_timeout_exit_error; - } } else if ( rc == 0 ) @@ -393,18 +381,15 @@ int _slurm_recv_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_ } else { - rc = _slurm_recv ( open_fd, &buffer[bytes_recv], (size-bytes_recv), flags ) ; + rc = _slurm_recv ( open_fd, &buffer[bytes_recv], + (size-bytes_recv), flags ) ; if ( (rc == SLURM_PROTOCOL_ERROR) || (rc < 0) ) { if ( errno == EINTR ) - { continue ; - } else - { goto _slurm_recv_timeout_exit_error; - } } else if ( rc == 0 ) { @@ -413,7 +398,7 @@ int _slurm_recv_timeout ( slurm_fd open_fd, char *buffer , size_t size , uint32_ } else { - bytes_recv+=rc ; + bytes_recv += rc ; break ; } } @@ -706,24 +691,22 @@ extern int _slurm_close (int __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 int _slurm_pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, sigset_t * sigmask) - { - return pselect ( n , readfds , writefds , exceptfds , timeout , sigmask ) ; - } - */ 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)