Skip to content

Commit

Permalink
add close
Browse files Browse the repository at this point in the history
  • Loading branch information
horbie committed Dec 4, 2016
1 parent 655cfc5 commit 9ffb0cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/utils/socket/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ bool Socket::Config(std::string addr, int port) {
}

bool Socket::Reconnect() {
return true;
Disconnect();
return Connect();
}

bool Socket::Connected() {
if (m_socketInst < 0) return false;
return true;
}

Expand All @@ -37,7 +39,14 @@ bool Socket::Connect() {
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(m_port);
inet_pton(AF_INET, m_addr.c_str(), &serverAddr.sin_addr);
connect(m_socketInst, (struct sockaddr*)&serverAddr, sizeof(serverAddr));
int isSuccess = connect(m_socketInst, (struct sockaddr*)&serverAddr, sizeof(serverAddr));
if (isSuccess < 0) return false;
return true;
}

bool Socket::Disconnect() {
if (m_socketInst < 0) return true;
close(m_socketInst);
return true;
}

1 change: 1 addition & 0 deletions src/utils/socket/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Socket {
protected:

bool Connect();
bool Disconnect();

};

Expand Down

0 comments on commit 9ffb0cf

Please sign in to comment.