[PATCH v2 01/11] sio: remove unused functions
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Wed Dec 5 00:28:46 MSK 2018
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)
More information about the Tarantool-patches
mailing list