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