@@ -75,26 +75,26 @@ { struct addrinfo hints, *res, *res0; char portstr[6]; if (!port) - @throw [OFInvalidPortException newWithObject: self]; + @throw [OFInvalidPortException newWithClass: [self class]]; if (sock != INVALID_SOCKET) - @throw [OFAlreadyConnectedException newWithObject: self]; + @throw [OFAlreadyConnectedException newWithClass: [self class]]; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; snprintf(portstr, 6, "%d", port); if (getaddrinfo(host, portstr, &hints, &res0)) @throw [OFAddressTranslationFailedException - newWithObject: self - andNode: host - andService: portstr]; + newWithClass: [self class] + andNode: host + andService: portstr]; for (res = res0; res != NULL; res = res->ai_next) { if ((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == INVALID_SOCKET) continue; @@ -109,13 +109,13 @@ } freeaddrinfo(res0); if (sock == INVALID_SOCKET) - @throw [OFConnectionFailedException newWithObject: self - andHost: host - andPort: port]; + @throw [OFConnectionFailedException newWithClass: [self class] + andHost: host + andPort: port]; return self; } - bindOn: (const char*)host @@ -124,39 +124,39 @@ { struct addrinfo hints, *res; char portstr[6]; if (!port) - @throw [OFInvalidPortException newWithObject: self]; + @throw [OFInvalidPortException newWithClass: [self class]]; if (sock != INVALID_SOCKET) - @throw [OFAlreadyConnectedException newWithObject: self]; + @throw [OFAlreadyConnectedException newWithClass: [self class]]; if ((sock = socket(family, SOCK_STREAM, 0)) == INVALID_SOCKET) - @throw [OFBindFailedException newWithObject: self - andHost: host - andPort: port - andFamily: family]; + @throw [OFBindFailedException newWithClass: [self class] + andHost: host + andPort: port + andFamily: family]; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = family; hints.ai_socktype = SOCK_STREAM; snprintf(portstr, 6, "%d", port); if (getaddrinfo(host, portstr, &hints, &res)) @throw [OFAddressTranslationFailedException - newWithObject: self - andNode: host - andService: portstr]; + newWithClass: [self class] + andNode: host + andService: portstr]; if (bind(sock, res->ai_addr, res->ai_addrlen) == -1) { freeaddrinfo(res); - @throw [OFBindFailedException newWithObject: self - andHost: host - andPort: port - andFamily: family]; + @throw [OFBindFailedException newWithClass: [self class] + andHost: host + andPort: port + andFamily: family]; } freeaddrinfo(res); return self; @@ -163,27 +163,27 @@ } - listenWithBackLog: (int)backlog { if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithObject: self]; + @throw [OFNotConnectedException newWithClass: [self class]]; if (listen(sock, backlog) == -1) - @throw [OFListenFailedException newWithObject: self - andBackLog: backlog]; + @throw [OFListenFailedException newWithClass: [self class] + andBackLog: backlog]; return self; } - listen { if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithObject: self]; + @throw [OFNotConnectedException newWithClass: [self class]]; if (listen(sock, 5) == -1) - @throw [OFListenFailedException newWithObject: self - andBackLog: 5]; + @throw [OFListenFailedException newWithClass: [self class] + andBackLog: 5]; return self; } - (OFTCPSocket*)accept @@ -203,11 +203,11 @@ @throw e; } if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) { [newsock free]; - @throw [OFAcceptFailedException newWithObject: self]; + @throw [OFAcceptFailedException newWithClass: [self class]]; } [newsock setSocket: s]; [newsock setSocketAddress: addr withLength: addrlen]; @@ -219,15 +219,15 @@ intoBuffer: (uint8_t*)buf { ssize_t ret; if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithObject: self]; + @throw [OFNotConnectedException newWithClass: [self class]]; if ((ret = recv(sock, (char*)buf, size, 0)) < 1) - @throw [OFReadFailedException newWithObject: self - andSize: size]; + @throw [OFReadFailedException newWithClass: [self class] + andSize: size]; /* This is safe, as we already checked < 1 */ return ret; } @@ -234,11 +234,11 @@ - (uint8_t*)readNBytes: (size_t)size { uint8_t *ret; if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithObject: self]; + @throw [OFNotConnectedException newWithClass: [self class]]; ret = [self getMemWithSize: size]; @try { [self readNBytes: size @@ -255,24 +255,24 @@ fromBuffer: (const uint8_t*)buf { ssize_t ret; if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithObject: self]; + @throw [OFNotConnectedException newWithClass: [self class]]; if ((ret = send(sock, (char*)buf, size, 0)) == -1) - @throw [OFWriteFailedException newWithObject: self - andSize: size]; + @throw [OFWriteFailedException newWithClass: [self class] + andSize: size]; /* This is safe, as we already checked for -1 */ return ret; } - (size_t)writeCString: (const char*)str { if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithObject: self]; + @throw [OFNotConnectedException newWithClass: [self class]]; return [self writeNBytes: strlen(str) fromBuffer: (const uint8_t*)str]; } @@ -280,24 +280,24 @@ { #ifndef _WIN32 int flags; if ((flags = fcntl(sock, F_GETFL)) == -1) - @throw [OFSetOptionFailedException newWithObject: self]; + @throw [OFSetOptionFailedException newWithClass: [self class]]; if (enable) flags &= ~O_NONBLOCK; else flags |= O_NONBLOCK; if (fcntl(sock, F_SETFL, flags) == -1) - @throw [OFSetOptionFailedException newWithObject: self]; + @throw [OFSetOptionFailedException newWithClass: [self class]]; #else u_long v = enable; if (ioctlsocket(sock, FIONBIO, &v) == SOCKET_ERROR) - @throw [OFSetOptionFailedException newWithObject: self]; + @throw [OFSetOptionFailedException newWithClass: [self class]]; #endif return self; } @@ -304,19 +304,19 @@ - enableKeepAlives: (BOOL)enable { int v = enable; if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, sizeof(v))) - @throw [OFSetOptionFailedException newWithObject: self]; + @throw [OFSetOptionFailedException newWithClass: [self class]]; return self; } - close { if (sock == INVALID_SOCKET) - @throw [OFNotConnectedException newWithObject: self]; + @throw [OFNotConnectedException newWithClass: [self class]]; sock = INVALID_SOCKET; if (saddr != NULL) [self freeMem: saddr];