Skip to content

Commit 97bfc02

Browse files
committed
refactor
1 parent 2f504fc commit 97bfc02

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/simple_socket/SocketConnection.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ namespace simple_socket {
4343
SocketConnection::close();
4444
}
4545

46+
operator SOCKET() const {
47+
return sockfd_;
48+
}
49+
50+
private:
4651
SOCKET sockfd_;
4752
};
4853

src/simple_socket/TCPSocket.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ struct TCPServer::Impl {
6464
serv_addr.sin_addr.s_addr = INADDR_ANY;
6565
serv_addr.sin_port = htons(port);
6666

67-
if (::bind(socket.sockfd_, reinterpret_cast<sockaddr*>(&serv_addr), sizeof(serv_addr)) < 0) {
67+
if (::bind(socket, reinterpret_cast<sockaddr*>(&serv_addr), sizeof(serv_addr)) < 0) {
6868

6969
throwSocketError("Bind failed");
7070
}
7171

72-
if (::listen(socket.sockfd_, backlog) < 0) {
72+
if (::listen(socket, backlog) < 0) {
7373

7474
throwSocketError("Listen failed");
7575
}
@@ -78,7 +78,7 @@ struct TCPServer::Impl {
7878
std::unique_ptr<SimpleConnection> accept() {
7979
sockaddr_in client_addr{};
8080
socklen_t addrlen = sizeof(client_addr);
81-
SOCKET new_sock = ::accept(socket.sockfd_, reinterpret_cast<sockaddr*>(&client_addr), &addrlen);
81+
SOCKET new_sock = ::accept(socket, reinterpret_cast<sockaddr*>(&client_addr), &addrlen);
8282

8383
if (new_sock == INVALID_SOCKET) {
8484

src/simple_socket/UnixDomainSocket.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ struct UnixDomainServer::Impl {
4444
addr.sun_family = AF_UNIX;
4545
strncpy(addr.sun_path, domain.c_str(), sizeof(addr.sun_path) - 1);
4646

47-
if (::bind(socket.sockfd_, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) {
47+
if (::bind(socket, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) {
4848

4949
throwSocketError("Bind failed");
5050
}
5151

52-
if (::listen(socket.sockfd_, backlog) < 0) {
52+
if (::listen(socket, backlog) < 0) {
5353

5454
throwSocketError("Listen failed");
5555
}
5656
}
5757

5858
std::unique_ptr<SocketConnection> accept() {
5959

60-
SOCKET new_sock = ::accept(socket.sockfd_, nullptr, nullptr);
60+
SOCKET new_sock = ::accept(socket, nullptr, nullptr);
6161
if (new_sock == INVALID_SOCKET) {
6262

6363
throwSocketError("Accept failed");

0 commit comments

Comments
 (0)