일단 거의 모든 버그 다 고칢..
This commit is contained in:
@@ -15,8 +15,8 @@ Socket::~Socket() {
|
||||
int Socket::init(int domain, int type, int protocol) {
|
||||
this->domain = domain;
|
||||
|
||||
sock_ = ::socket(domain, type, protocol);
|
||||
if (sock_ == INVALID_SOCKET)
|
||||
sock = ::socket(domain, type, protocol);
|
||||
if (sock == INVALID_SOCKET)
|
||||
log::critical("socket()");
|
||||
|
||||
valid_ = true;
|
||||
@@ -28,9 +28,9 @@ void Socket::destruct() {
|
||||
if (!valid_)
|
||||
return;
|
||||
#ifdef _WIN32
|
||||
::closesocket(sock_);
|
||||
::closesocket(sock);
|
||||
#elif __linux__
|
||||
::close(sock_);
|
||||
::close(sock);
|
||||
#endif
|
||||
valid_ = false;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ void Socket::destruct() {
|
||||
Socket::operator SOCKET() {
|
||||
if (valid_) {
|
||||
valid_ = false;
|
||||
return sock_;
|
||||
return sock;
|
||||
}
|
||||
spdlog::critical("No valid socket created.");
|
||||
return INVALID_SOCKET;
|
||||
@@ -50,41 +50,41 @@ void Socket::set(const SOCKET __sock, int __domain) {
|
||||
|
||||
destruct();
|
||||
|
||||
sock_ = __sock;
|
||||
sock = __sock;
|
||||
valid_ = true;
|
||||
};
|
||||
|
||||
int Socket::bind(Address __addr) {
|
||||
bindAddr = __addr;
|
||||
int retVal = ::bind(sock_, &__addr.addr, __addr.length);
|
||||
int retVal = ::bind(sock, &__addr.addr, __addr.length);
|
||||
if (retVal == INVALID_SOCKET)
|
||||
log::critical("bind()");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int Socket::recvfrom(void *__restrict __buf, size_t __n, int __flags, struct Address& __addr) {
|
||||
int retVal = ::recvfrom(sock_, (char*)__buf, __n, __flags, &__addr.addr, &__addr.length);
|
||||
int retVal = ::recvfrom(sock, (char*)__buf, __n, __flags, &__addr.addr, &__addr.length);
|
||||
if (retVal == SOCKET_ERROR)
|
||||
log::error("recvfrom()");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int Socket::sendto(const void *__buf, size_t __n, int __flags, struct Address __addr) {
|
||||
int retVal = ::sendto(sock_, (char*)__buf, __n, __flags, &__addr.addr, __addr.length);
|
||||
int retVal = ::sendto(sock, (char*)__buf, __n, __flags, &__addr.addr, __addr.length);
|
||||
if (retVal == SOCKET_ERROR)
|
||||
log::error("sendto()");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
Socket::Socket(Socket &&other_) {
|
||||
Socket::Socket(Socket &&other_) noexcept {
|
||||
other_.valid_ = false;
|
||||
sock_ = other_.sock_;
|
||||
memcpy(this, &other_, sizeof(Socket));
|
||||
valid_ = true;
|
||||
}
|
||||
|
||||
Socket& Socket::operator=(Socket && other_) {
|
||||
Socket& Socket::operator=(Socket && other_) noexcept {
|
||||
other_.valid_ = false;
|
||||
sock_ = other_.sock_;
|
||||
memcpy(this, &other_, sizeof(Socket));
|
||||
valid_ = true;
|
||||
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user