From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [PATCH 03/11] sio: remove exceptions
Date: Mon, 3 Dec 2018 15:36:42 +0300 [thread overview]
Message-ID: <20181203123642.hpo5nhkndt7qftcl@esperanza> (raw)
In-Reply-To: <14e50e3a3872a1898d5df006fb61442c1ab2e556.1543590433.git.v.shpilevoy@tarantool.org>
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)
?
next prev parent reply other threads:[~2018-12-03 12:36 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-30 15:39 [PATCH 00/11] SWIM preparation Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 01/11] box: move info_handler interface into src/info Vladislav Shpilevoy
2018-12-03 11:05 ` Vladimir Davydov
2018-12-03 21:48 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-03 20:41 ` [tarantool-patches] " Konstantin Osipov
2018-12-03 21:48 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-04 8:52 ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 10/11] evio: remove exceptions Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 11/11] evio: turn into C Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 02/11] sio: remove unused functions, restyle code Vladislav Shpilevoy
2018-12-03 12:28 ` Vladimir Davydov
2018-12-04 21:29 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-05 8:41 ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 03/11] sio: remove exceptions Vladislav Shpilevoy
2018-12-03 12:36 ` Vladimir Davydov [this message]
2018-12-04 21:29 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-05 8:42 ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 04/11] sio: fix passing negative size_t to sio_add_to_iov Vladislav Shpilevoy
2018-12-03 13:50 ` Vladimir Davydov
2018-12-04 21:29 ` Vladislav Shpilevoy
2018-12-05 8:48 ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 05/11] sio: turn into C Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 06/11] evio: make on_accept be nothrow Vladislav Shpilevoy
2018-12-03 14:58 ` Vladimir Davydov
2018-12-04 21:29 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-05 8:52 ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 07/11] coio: fix file descriptor leak on accept Vladislav Shpilevoy
2018-12-03 16:16 ` Vladimir Davydov
2018-12-04 21:29 ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 08/11] coio: fix double close of a file descriptor Vladislav Shpilevoy
2018-12-03 16:19 ` Vladimir Davydov
2018-12-04 21:29 ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 09/11] evio: refactoring Vladislav Shpilevoy
2018-12-03 16:37 ` Vladimir Davydov
2018-12-04 21:29 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-03 9:47 ` [PATCH 00/11] SWIM preparation Vladimir Davydov
2018-12-03 10:27 ` [tarantool-patches] " Vladislav Shpilevoy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181203123642.hpo5nhkndt7qftcl@esperanza \
--to=vdavydov.dev@gmail.com \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [PATCH 03/11] sio: remove exceptions' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox