Branch data Line data Source code
1 : : /*
2 : : * Copyright 2025 Jinwoo Sung
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * http://www.apache.org/licenses/LICENSE-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : #include "wirestead/transport/tcp_server/boost_tcp_socket.hpp"
18 : :
19 : : #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
20 : : #include <sys/socket.h>
21 : : #include <sys/types.h>
22 : : #endif
23 : :
24 : : namespace wirestead {
25 : : namespace transport {
26 : :
27 : : namespace net = boost::asio;
28 : : using tcp = net::ip::tcp;
29 : :
30 : 110 : BoostTcpSocket::BoostTcpSocket(tcp::socket sock) : socket_(std::move(sock)) {
31 : : #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
32 : : int yes = 1;
33 : : (void)::setsockopt(static_cast<int>(socket_.native_handle()), SOL_SOCKET, SO_NOSIGPIPE, &yes,
34 : : static_cast<socklen_t>(sizeof(yes)));
35 : : #endif
36 : 110 : }
37 : :
38 : 2581 : void BoostTcpSocket::async_read_some(const net::mutable_buffer& buffer,
39 : : std::function<void(const boost::system::error_code&, std::size_t)> handler) {
40 : 2581 : socket_.async_read_some(buffer, std::move(handler));
41 : 2581 : }
42 : :
43 : 0 : void BoostTcpSocket::async_write(const net::const_buffer& buffer,
44 : : std::function<void(const boost::system::error_code&, std::size_t)> handler) {
45 : 0 : net::async_write(socket_, buffer, std::move(handler));
46 : 0 : }
47 : :
48 : 107 : void BoostTcpSocket::shutdown(tcp::socket::shutdown_type what, boost::system::error_code& ec) {
49 : 107 : socket_.shutdown(what, ec);
50 : 107 : }
51 : :
52 : 108 : void BoostTcpSocket::close(boost::system::error_code& ec) { socket_.close(ec); }
53 : :
54 : 0 : tcp::endpoint BoostTcpSocket::remote_endpoint(boost::system::error_code& ec) const {
55 : 0 : return socket_.remote_endpoint(ec);
56 : : }
57 : :
58 : : } // namespace transport
59 : : } // namespace wirestead
|