From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [94.100.177.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id B65914696CE for ; Fri, 10 Apr 2020 05:51:27 +0300 (MSK) From: Alexander Turenko Date: Fri, 10 Apr 2020 05:50:50 +0300 Message-Id: <328813debe7020378d0faa79bc3eee8cd00f6197.1586486220.git.alexander.turenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 12/13] coio: add *_noxc read / write functions List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov Cc: tarantool-patches@dev.tarantool.org The popen implementation is written in C and uses coio read / write functions. If an exception occurs, it'll pass through the C code. It should be catched to proceed correctly. We usually have foo() and foo_xc() (exception) functions when both variants are necessary. Here I added non-conventional *_noxc() functions as the temporary solution to postpone refactoring of the code and all its usages. Part of #4031 --- src/lib/core/coio.cc | 39 +++++++++++++++++++++++++++++++++++++++ src/lib/core/coio.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/lib/core/coio.cc b/src/lib/core/coio.cc index 74e6240ce..6a113aa47 100644 --- a/src/lib/core/coio.cc +++ b/src/lib/core/coio.cc @@ -381,6 +381,26 @@ coio_readn_ahead_timeout(struct ev_io *coio, void *buf, size_t sz, size_t bufsiz return nrd; } +/* + * FIXME: Rewrite coio_read_ahead_timeout() w/o C++ exceptions and + * drop this function. + */ +ssize_t +coio_read_ahead_timeout_noxc(struct ev_io *coio, void *buf, size_t sz, + size_t bufsiz, ev_tstamp timeout) +{ + try { + return coio_read_ahead_timeout(coio, buf, sz, bufsiz, timeout); + } catch (Exception *) { + /* + * The exception is already in the diagnostics + * area. Nothing to do. + */ + } + return -1; +} + + /** Write sz bytes to socket. * * Throws SocketError in case of write error. If @@ -437,6 +457,25 @@ coio_write_timeout(struct ev_io *coio, const void *buf, size_t sz, } } +/* + * FIXME: Rewrite coio_write_timeout() w/o C++ exceptions and drop + * this function. + */ +ssize_t +coio_write_timeout_noxc(struct ev_io *coio, const void *buf, size_t sz, + ev_tstamp timeout) +{ + try { + return coio_write_timeout(coio, buf, sz, timeout); + } catch (Exception *) { + /* + * The exception is already in the diagnostics + * area. Nothing to do. + */ + } + return -1; +} + /* * Write iov using sio API. * Put in an own function to workaround gcc bug with @finally diff --git a/src/lib/core/coio.h b/src/lib/core/coio.h index c323955d7..7875a0da1 100644 --- a/src/lib/core/coio.h +++ b/src/lib/core/coio.h @@ -130,6 +130,29 @@ coio_read_timeout(struct ev_io *coio, void *buf, size_t sz, ev_tstamp timeout) return coio_read_ahead_timeout(coio, buf, sz, sz, timeout); } +/** + * Read data with timeout. + * + * Yield until some data will be available for read. + * + * Returns amount of read bytes at success, otherwise returns -1 + * and set a diag. + * + * Zero return value means EOF. + * + * Note: Less then @a count bytes may be available for read at a + * moment, so a return value less then @a count does not mean EOF. + * + * Possible errors: + * + * - SocketError: an IO error occurs at read(). + * - TimedOut: @a timeout quota is exceeded. + * - FiberIsCancelled: cancelled by an outside code. + */ +ssize_t +coio_read_ahead_timeout_noxc(struct ev_io *coio, void *buf, size_t sz, + size_t bufsiz, ev_tstamp timeout); + static inline ssize_t coio_readn(struct ev_io *coio, void *buf, size_t sz) { @@ -144,6 +167,24 @@ ssize_t coio_write_timeout(struct ev_io *coio, const void *buf, size_t sz, ev_tstamp timeout); +/** + * Write @a count bytes with timeout. + * + * Yield until all @a count bytes will be written. + * + * Returns @a count at success, otherwise returns -1 and set a + * diag. + * + * Possible errors: + * + * - SocketError: an IO error occurs at write(). + * - TimedOut: @a timeout quota is exceeded. + * - FiberIsCancelled: cancelled by an outside code. + */ +ssize_t +coio_write_timeout_noxc(struct ev_io *coio, const void *buf, size_t sz, + ev_tstamp timeout); + static inline void coio_write(struct ev_io *coio, const void *buf, size_t sz) { -- 2.25.0