[PATCH 03/11] sio: remove exceptions
Vladimir Davydov
vdavydov.dev at gmail.com
Mon Dec 3 15:36:42 MSK 2018
On Fri, Nov 30, 2018 at 06:39:35PM +0300, Vladislav Shpilevoy wrote:
> diff --git a/src/sio.h b/src/sio.h
> index d937cfd3d..ab0a243cd 100644
> --- a/src/sio.h
> +++ b/src/sio.h
> @@ -151,57 +151,110 @@ sio_bind(int fd, struct sockaddr *addr, socklen_t addrlen);
>
> /**
> * Mark a socket as accepting connections. A wrapper for listen(),
> - * but throws exception on error.
> + * but sets diagnostics on error.
> */
> int
> sio_listen(int fd);
>
> /**
> * Accept a client connection on a server socket. A wrapper for
> - * accept(), but throws exception on error except EAGAIN, EINTR,
> + * accept(), but sets diagnostics on error except EAGAIN, EINTR,
> * EWOULDBLOCK.
> + * @param fd Server socket.
> + * @param[out] addr Accepted client's address.
> + * @param[in, out] addrlen Size of @a addr.
> + * @param[out] is_error_fatal Set to true, if an error occured and
> + * it was not EAGAIN, EINTR and EWOULDBLOCK.
> + *
> + * @retval Client socket, or -1 on error.
> */
> int
> -sio_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
> +sio_accept(int fd, struct sockaddr *addr, socklen_t *addrlen,
> + bool *is_error_fatal);
>
> /**
> * Read up to @a count bytes from a socket. A wrapper for read(),
> - * but throws exception on error except EWOULDBLOCK, EINTR,
> + * but sets diagnostics on error except EWOULDBLOCK, EINTR,
> * EAGAIN, ECONNRESET.
> + * @param fd Socket.
> + * @param buf Buffer to read into.
> + * @param count How many bytes to read.
> + * @param[out] is_error_fatal Set to true, if an error occured and
> + * it was not EAGAIN, EINTR, ECONNRESET and
> + * EWOULDBLOCK.
> + *
> + * @retval How many bytes are read, or -1 on error.
> */
> ssize_t
> -sio_read(int fd, void *buf, size_t count);
> +sio_read(int fd, void *buf, size_t count, bool *is_error_fatal);
>
> /**
> * Write up to @a count bytes to a socket. A wrapper for write(),
> - * but throws exception on error except EAGAIN, EINTR,
> + * but sets diagnostics on error except EAGAIN, EINTR,
> * EWOULDBLOCK.
> + * @param fd Socket.
> + * @param buf Buffer to write.
> + * @param count How many bytes to write.
> + * @param[out] is_error_fatal Set to true, if an error occured and
> + * it was not EAGAIN, EINTR and EWOULDBLOCK.
> + *
> + * @retval How many bytes are written, or -1 on error.
> */
> ssize_t
> -sio_write(int fd, const void *buf, size_t count);
> +sio_write(int fd, const void *buf, size_t count, bool *is_error_fatal);
>
> /**
> * Write @a iov vector to a socket. A wrapper for writev(), but
> - * throws exception on error except EAGAIN, EINTR, EWOULDBLOCK.
> + * sets diagnostics on error except EAGAIN, EINTR, EWOULDBLOCK.
> + * @param fd Socket.
> + * @param iov Vector to write.
> + * @param iovcnt Size of @a iov.
> + * @param[out] is_error_fatal Set to true, if an error occured and
> + * it was not EAGAIN, EINTR and EWOULDBLOCK.
> + *
> + * @retval How many bytes are written, or -1 on error.
> */
> ssize_t
> -sio_writev(int fd, const struct iovec *iov, int iovcnt);
> +sio_writev(int fd, const struct iovec *iov, int iovcnt,
> + bool *is_error_fatal);
>
> /**
> - * Send a message on a socket. A wrapper for sendto(), but throws
> - * exception on error except EAGAIN, EINTR, EWOULDBLOCK.
> + * Send a message on a socket. A wrapper for sendto(), but sets
> + * diagnostics on error except EAGAIN, EINTR, EWOULDBLOCK.
> + * @param fd Socket to send to.
> + * @param buf Buffer to send.
> + * @param len Size of @a buf.
> + * @param flags sendto() flags.
> + * @param dest_addr Destination address.
> + * @param addrlen Size of @a dest_addr.
> + * @param[out] is_error_fatal Set to true, if an error occured and
> + * it was not EAGAIN, EINTR and EWOULDBLOCK.
> + *
> + * @param How many bytes are sent, or -1 on error.
> */
> ssize_t
> sio_sendto(int fd, const void *buf, size_t len, int flags,
> - const struct sockaddr *dest_addr, socklen_t addrlen);
> + const struct sockaddr *dest_addr, socklen_t addrlen,
> + bool *is_error_fatal);
>
> /**
> * Receive a message on a socket. A wrapper for recvfrom(), but
> - * throws exception on error except EAGAIN, EINTR, EWOULDBLOCK.
> + * sets diagnostics on error except EAGAIN, EINTR, EWOULDBLOCK.
> + * @param fd Socket to receive from.
> + * @param buf Buffer to save message.
> + * @param len Size of @a buf.
> + * @param flags recvfrom() flags.
> + * @param[out] src_addr Source address.
> + * @param[in, out] addrlen Size of @a src_addr.
> + * @param[out] is_error_fatal Set to true, if an error occured and
> + * it was not EAGAIN, EINTR and EWOULDBLOCK.
> + *
> + * @param How many bytes are received, or -1 on error.
> */
> ssize_t
> sio_recvfrom(int fd, void *buf, size_t len, int flags,
> - struct sockaddr *src_addr, socklen_t *addrlen);
> + struct sockaddr *src_addr, socklen_t *addrlen,
> + bool *is_error_fatal);
This new API doesn't look good to me. Let's instead set diag and return
-1 on every error and introduce a helper to check if a particular error
code means that the socket would block (the name might need to be
refined):
sio_wouldblock(errno)
?
More information about the Tarantool-patches
mailing list