mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 05:21:49 +00:00
fix some small issues in Network.cpp
This commit is contained in:
parent
e9a7a32249
commit
e3c86cd1da
1 changed files with 5 additions and 4 deletions
|
|
@ -319,7 +319,6 @@ public:
|
||||||
~SocketConnection() {
|
~SocketConnection() {
|
||||||
if (state != ConnectionState::CLOSED) {
|
if (state != ConnectionState::CLOSED) {
|
||||||
shutdown(descriptor, 2);
|
shutdown(descriptor, 2);
|
||||||
closesocket(descriptor);
|
|
||||||
}
|
}
|
||||||
if (thread) {
|
if (thread) {
|
||||||
thread->join();
|
thread->join();
|
||||||
|
|
@ -382,6 +381,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
int send(const char* buffer, size_t length) override {
|
int send(const char* buffer, size_t length) override {
|
||||||
|
if (state == ConnectionState::CLOSED) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int len = sendsocket(descriptor, buffer, length, 0);
|
int len = sendsocket(descriptor, buffer, length, 0);
|
||||||
if (len == -1) {
|
if (len == -1) {
|
||||||
int err = errno;
|
int err = errno;
|
||||||
|
|
@ -444,7 +446,7 @@ public:
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
addrinfo* addrinfo;
|
addrinfo* addrinfo = nullptr;
|
||||||
if (int res = getaddrinfo(
|
if (int res = getaddrinfo(
|
||||||
address.c_str(), nullptr, &hints, &addrinfo
|
address.c_str(), nullptr, &hints, &addrinfo
|
||||||
)) {
|
)) {
|
||||||
|
|
@ -452,12 +454,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
sockaddr_in serverAddress = *(sockaddr_in*)addrinfo->ai_addr;
|
sockaddr_in serverAddress = *(sockaddr_in*)addrinfo->ai_addr;
|
||||||
freeaddrinfo(addrinfo);
|
|
||||||
serverAddress.sin_port = htons(port);
|
serverAddress.sin_port = htons(port);
|
||||||
|
freeaddrinfo(addrinfo);
|
||||||
|
|
||||||
SOCKET descriptor = socket(AF_INET, SOCK_STREAM, 0);
|
SOCKET descriptor = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (descriptor == -1) {
|
if (descriptor == -1) {
|
||||||
freeaddrinfo(addrinfo);
|
|
||||||
throw std::runtime_error("Could not create socket");
|
throw std::runtime_error("Could not create socket");
|
||||||
}
|
}
|
||||||
auto socket = std::make_shared<SocketConnection>(descriptor, std::move(serverAddress));
|
auto socket = std::make_shared<SocketConnection>(descriptor, std::move(serverAddress));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue