| 1 | |
| 2 | // vim:sw=2:ai |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved. |
| 6 | * See COPYRIGHT.txt for details. |
| 7 | */ |
| 8 | |
| 9 | #ifndef DENA_SOCKET_HPP |
| 10 | #define DENA_SOCKET_HPP |
| 11 | |
| 12 | #include <string> |
| 13 | |
| 14 | #include "auto_addrinfo.hpp" |
| 15 | #include "auto_file.hpp" |
| 16 | #include "config.hpp" |
| 17 | |
| 18 | namespace dena { |
| 19 | |
| 20 | struct socket_args { |
| 21 | sockaddr_storage addr; |
| 22 | size_socket addrlen; |
| 23 | int family; |
| 24 | int socktype; |
| 25 | int protocol; |
| 26 | int timeout; |
| 27 | int listen_backlog; |
| 28 | bool reuseaddr; |
| 29 | bool nonblocking; |
| 30 | bool use_epoll; |
| 31 | int sndbuf; |
| 32 | int rcvbuf; |
| 33 | socket_args() : addr(), addrlen(0), family(AF_INET), socktype(SOCK_STREAM), |
| 34 | protocol(0), timeout(600), listen_backlog(256), |
| 35 | reuseaddr(true), nonblocking(false), use_epoll(false), |
| 36 | sndbuf(0), rcvbuf(0) { } |
| 37 | void set(const config& conf); |
| 38 | void set_unix_domain(const char *path); |
| 39 | int resolve(const char *node, const char *service); |
| 40 | }; |
| 41 | |
| 42 | void ignore_sigpipe(); |
| 43 | int socket_bind(auto_file& fd, const socket_args& args, std::string& err_r); |
| 44 | int socket_connect(auto_file& fd, const socket_args& args, std::string& err_r); |
| 45 | int socket_accept(int listen_fd, auto_file& fd, const socket_args& args, |
| 46 | sockaddr_storage& addr_r, size_socket& addrlen_r, std::string& err_r); |
| 47 | |
| 48 | }; |
| 49 | |
| 50 | #endif |
| 51 | |
| 52 | |