Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com
Subject: [PATCH v2 01/11] sio: remove unused functions
Date: Wed,  5 Dec 2018 00:28:46 +0300	[thread overview]
Message-ID: <1a485fb50c67a57039ac503919476d9a1a4f1d3c.1543958698.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1543958698.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1543958698.git.v.shpilevoy@tarantool.org>

Next patches remove exceptions from sio and convert it
to C. So as to do not care about unused functions they
are deleted.
---
 src/sio.cc | 166 +----------------------------------------------------
 src/sio.h  |  54 -----------------
 2 files changed, 1 insertion(+), 219 deletions(-)

diff --git a/src/sio.cc b/src/sio.cc
index 0475b9e83..d79ad5c01 100644
--- a/src/sio.cc
+++ b/src/sio.cc
@@ -33,18 +33,9 @@
 #include <sys/un.h>
 #include <sys/uio.h>
 #include <errno.h>
-#include <stdio.h>
 #include <limits.h>
 #include <netinet/in.h> /* TCP_NODELAY */
 #include <netinet/tcp.h> /* TCP_NODELAY */
-#include <arpa/inet.h> /* inet_ntoa */
-#include <poll.h>
-#include <unistd.h> /* lseek for sending file */
-#include <sys/stat.h> /* fstat for sending file */
-#ifdef TARGET_OS_LINUX
-#include <sys/sendfile.h> /* sendfile system call */
-#endif /* #ifdef TARGET_OS_LINUX */
-
 #include "say.h"
 #include "trivia/util.h"
 #include "exception.h"
@@ -107,22 +98,12 @@ sio_option_name(int option)
 #undef CASE_OPTION
 }
 
-/** shut down part of a full-duplex connection */
-int
-sio_shutdown(int fd, int how)
-{
-	int rc = shutdown(fd, how);
-	if (rc < 0)
-		diag_set(SocketError, sio_socketname(fd), "shutdown");
-	return rc;
-}
-
 /** Try to automatically configure a listen backlog.
  * On Linux, use the system setting, which defaults
  * to 128. This way a system administrator can tune
  * the backlog as needed. On other systems, use SOMAXCONN.
  */
-int
+static int
 sio_listen_backlog()
 {
 #ifdef TARGET_OS_LINUX
@@ -305,151 +286,6 @@ sio_writev(int fd, const struct iovec *iov, int iovcnt)
 	return n;
 }
 
-/** Blocking I/O writev */
-ssize_t
-sio_writev_all(int fd, struct iovec *iov, int iovcnt)
-{
-	ssize_t bytes_total = 0;
-	struct iovec *iovend = iov + iovcnt;
-	while (1) {
-		int cnt = iovend - iov;
-		if (cnt > IOV_MAX)
-			cnt = IOV_MAX;
-		ssize_t write_res = writev(fd, iov, cnt);
-		if (write_res < 0) {
-			if (errno == EINTR)
-				continue;
-			tnt_raise(SocketError, sio_socketname(fd),
-				  "writev(%d)", cnt);
-		}
-                size_t bytes_written = (size_t)write_res;
-		bytes_total += bytes_written;
-		/*
-		 * Check for iov < iovend, since otherwise
-		 * if iovend->iov_len is 0, iov may go beyond
-		 * iovend
-		 */
-		while (bytes_written >= iov->iov_len) {
-			bytes_written -= (iov++)->iov_len;
-			if (iov == iovend)
-				break;
-		}
-		if (iov == iovend)
-			break;
-		iov->iov_base = (char *) iov->iov_base + bytes_written;
-		iov->iov_len -= bytes_written;
-	}
-	return bytes_total;
-}
-
-ssize_t
-sio_readn_ahead(int fd, void *buf, size_t count, size_t buf_size)
-{
-	size_t read_count = 0;
-	while (read_count < count) {
-		ssize_t read_res = read(fd, (char *) buf + read_count,
-					buf_size - read_count);
-		if (read_res < 0 && (errno == EWOULDBLOCK ||
-				     errno == EINTR || errno == EAGAIN))
-			continue;
-
-		if (read_res <= 0)
-			tnt_raise(SocketError, sio_socketname(fd),
-				  "read (%zd)", count);
-
-		read_count += read_res;
-	}
-	return read_count;
-}
-
-ssize_t
-sio_writen(int fd, const void *buf, size_t count)
-{
-	size_t write_count = 0;
-	while (write_count < count) {
-		ssize_t write_res = write(fd, (char *) buf + write_count,
-					  count - write_count);
-		if (write_res < 0 && (errno == EWOULDBLOCK ||
-				      errno == EINTR || errno == EAGAIN))
-			continue;
-
-		if (write_res <= 0)
-			tnt_raise(SocketError, sio_socketname(fd),
-				  "write (%zd)", count);
-
-		write_count += write_res;
-	}
-	return write_count;
-}
-
-static inline off_t
-sio_lseek(int fd, off_t offset, int whence)
-{
-	off_t res = lseek(fd, offset, whence);
-	if (res == -1)
-		tnt_raise(SocketError, sio_socketname(fd),
-			  "lseek");
-	return res;
-}
-
-#if defined(HAVE_SENDFILE_LINUX)
-ssize_t
-sio_sendfile(int sock_fd, int file_fd, off_t *offset, size_t size)
-{
-	ssize_t send_res = sendfile(sock_fd, file_fd, offset, size);
-	if (send_res < 0 || (size_t)send_res < size)
-		tnt_raise(SocketError, sio_socketname(sock_fd),
-			  "sendfile");
-	return send_res;
-}
-#else
-ssize_t
-sio_sendfile(int sock_fd, int file_fd, off_t *offset, size_t size)
-{
-	if (offset)
-		sio_lseek(file_fd, *offset, SEEK_SET);
-
-	const size_t buffer_size = 8192;
-	char buffer[buffer_size];
-	size_t bytes_sent = 0;
-	while (bytes_sent < size) {
-		size_t to_send_now = MIN(size - bytes_sent, buffer_size);
-		ssize_t n = sio_read(file_fd, buffer, to_send_now);
-		sio_writen(sock_fd, buffer, n);
-		bytes_sent += n;
-	}
-
-	if (offset)
-		lseek(file_fd, *offset, SEEK_SET);
-
-	return bytes_sent;
-}
-#endif
-
-ssize_t
-sio_recvfile(int sock_fd, int file_fd, off_t *offset, size_t size)
-{
-	if (offset)
-		sio_lseek(file_fd, *offset, SEEK_SET);
-
-	const size_t buffer_size = 8192;
-	char buffer[buffer_size];
-	size_t bytes_read = 0;
-	while (bytes_read < size) {
-		size_t to_read_now = MIN(size - bytes_read, buffer_size);
-		ssize_t n = sio_read(sock_fd, buffer, to_read_now);
-		if (n < 0)
-			return -1;
-		sio_writen(file_fd, buffer, n);
-		bytes_read += n;
-	}
-
-	if (offset)
-		sio_lseek(file_fd, *offset, SEEK_SET);
-
-	return bytes_read;
-}
-
 /** Send a message on a socket. */
 ssize_t
 sio_sendto(int fd, const void *buf, size_t len, int flags,
diff --git a/src/sio.h b/src/sio.h
index f728af547..2843c0c45 100644
--- a/src/sio.h
+++ b/src/sio.h
@@ -95,8 +95,6 @@ sio_add_to_iov(struct iovec *iov, size_t size)
 const char *sio_socketname(int fd);
 int sio_socket(int domain, int type, int protocol);
 
-int sio_shutdown(int fd, int how);
-
 int sio_getfl(int fd);
 int sio_setfl(int fd, int flag, int on);
 
@@ -110,7 +108,6 @@ sio_getsockopt(int fd, int level, int optname,
 int sio_connect(int fd, struct sockaddr *addr, socklen_t addrlen);
 int sio_bind(int fd, struct sockaddr *addr, socklen_t addrlen);
 int sio_listen(int fd);
-int sio_listen_backlog();
 int sio_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
 
 ssize_t sio_read(int fd, void *buf, size_t count);
@@ -118,57 +115,6 @@ ssize_t sio_read(int fd, void *buf, size_t count);
 ssize_t sio_write(int fd, const void *buf, size_t count);
 ssize_t sio_writev(int fd, const struct iovec *iov, int iovcnt);
 
-ssize_t sio_write_total(int fd, const void *buf, size_t count, size_t total);
-
-/**
- * Read at least count and up to buf_size bytes from fd.
- * Throw exception on error or disconnect.
- *
- * @return the number of of bytes actually read.
- */
-ssize_t
-sio_readn_ahead(int fd, void *buf, size_t count, size_t buf_size);
-
-/**
- * Read count bytes from fd.
- * Throw an exception on error or disconnect.
- *
- * @return count of bytes actually read.
- */
-static inline ssize_t
-sio_readn(int fd, void *buf, size_t count)
-{
-	return sio_readn_ahead(fd, buf, count, count);
-}
-
-/**
- * Write count bytes to fd.
- * Throw an exception on error or disconnect.
- *
- * @return count of bytes actually written.
- */
-ssize_t
-sio_writen(int fd, const void *buf, size_t count);
-
-/* Only for blocked I/O */
-ssize_t
-sio_writev_all(int fd, struct iovec *iov, int iovcnt);
-
-/**
- * A wrapper over sendfile.
- * Throw if send file failed.
- */
-ssize_t
-sio_sendfile(int sock_fd, int file_fd, off_t *offset, size_t size);
-
-/**
- * Receive a file sent by sendfile
- * Throw if receiving failed
- */
-ssize_t
-sio_recvfile(int sock_fd, int file_fd, off_t *offset, size_t size);
-
-
 ssize_t sio_sendto(int fd, const void *buf, size_t len, int flags,
 		   const struct sockaddr *dest_addr, socklen_t addrlen);
 
-- 
2.17.2 (Apple Git-113)

  reply	other threads:[~2018-12-04 21:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-04 21:28 [PATCH v2 00/11] SWIM preparation Vladislav Shpilevoy
2018-12-04 21:28 ` Vladislav Shpilevoy [this message]
2018-12-09 12:10   ` [PATCH v2 01/11] sio: remove unused functions Vladimir Davydov
2018-12-04 21:28 ` [PATCH v2 10/11] evio: make code C compatible Vladislav Shpilevoy
2018-12-05  8:56   ` Vladimir Davydov
2018-12-05 20:07     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-04 21:28 ` [PATCH v2 11/11] evio: turn nto c Vladislav Shpilevoy
2018-12-04 21:28 ` [PATCH v2 02/11] sio: treat EADDRINUSE in sio_listen as error Vladislav Shpilevoy
2018-12-09 12:57   ` Vladimir Davydov
2018-12-10 15:36     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-04 21:28 ` [PATCH v2 03/11] sio: remove exceptions Vladislav Shpilevoy
2018-12-09 12:54   ` Vladimir Davydov
2018-12-10 15:37     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-11  8:44       ` Vladimir Davydov
2018-12-04 21:28 ` [PATCH v2 04/11] sio: make code compatible with C Vladislav Shpilevoy
2018-12-05  8:57   ` Vladimir Davydov
2018-12-05 20:07     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-04 21:28 ` [PATCH v2 05/11] sio: turn into C Vladislav Shpilevoy
2018-12-04 21:28 ` [PATCH v2 06/11] evio: make on_accept be nothrow Vladislav Shpilevoy
2018-12-04 21:28 ` [PATCH v2 07/11] coio: fix double close of a file descriptor Vladislav Shpilevoy
2018-12-04 21:28 ` [PATCH v2 08/11] evio: remove exceptions Vladislav Shpilevoy
2018-12-04 21:28 ` [PATCH v2 09/11] coio: fix file descriptor leak on accept Vladislav Shpilevoy
2018-12-11  8:47 ` [PATCH v2 00/11] SWIM preparation Vladimir Davydov

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=1a485fb50c67a57039ac503919476d9a1a4f1d3c.1543958698.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v2 01/11] sio: remove unused functions' \
    /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