@@ -64,14 +64,12 @@ if (!port) { /* FIXME: Throw exception */ return nil; } - if (sock >= 0) { - /* FIXME: Throw exception */ - return nil; - } + if (sock >= 0) + @throw [OFAlreadyConnectedException newWithObject: self]; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; @@ -116,14 +114,12 @@ if (!port) { /* FIXME: Throw exception */ return nil; } - if (sock >= 0) { - /* FIXME: Throw exception */ - return nil; - } + if (sock >= 0) + @throw [OFAlreadyConnectedException newWithObject: self]; if ((sock = socket(family, SOCK_STREAM, 0)) < 0) { /* FIXME: Throw exception */ return nil; } @@ -150,14 +146,12 @@ return self; } - listenWithBackLog: (int)backlog { - if (sock < 0) { - /* FIXME: Throw exception */ - return nil; - } + if (sock < 0) + @throw [OFNotConnectedException newWithObject: self]; if (listen(sock, backlog) < 0 ) { /* FIXME: Throw exception */ return nil; } @@ -165,14 +159,12 @@ return self; } - listen { - if (sock < 0) { - /* FIXME: Throw exception */ - return nil; - } + if (sock < 0) + @throw [OFNotConnectedException newWithObject: self]; if (listen(sock, 5) < 0 ) { /* FIXME: Throw exception */ return nil; } @@ -212,14 +204,12 @@ - (size_t)readNBytes: (size_t)size intoBuffer: (uint8_t*)buf { ssize_t ret; - if (sock < 0) { - /* FIXME: Throw exception */ - return 0; - } + if (sock < 0) + @throw [OFNotConnectedException newWithObject: self]; if ((ret = recv(sock, buf, size, 0)) < 0) { /* FIXME: Throw exception */ return 0; } @@ -230,14 +220,12 @@ - (uint8_t*)readNBytes: (size_t)size { uint8_t *ret; - if (sock < 0) { - /* FIXME: Throw exception */ - return NULL; - } + if (sock < 0) + @throw [OFNotConnectedException newWithObject: self]; ret = [self getMemWithSize: size]; @try { [self readNBytes: size @@ -253,14 +241,12 @@ - (size_t)writeNBytes: (size_t)size fromBuffer: (const uint8_t*)buf { ssize_t ret; - if (sock < 0) { - /* FIXME: Throw exception */ - return 0; - } + if (sock < 0) + @throw [OFNotConnectedException newWithObject: self]; if ((ret = send(sock, buf, size, 0)) < 0) { /* FIXME: Throw exception */ return 0; } @@ -269,25 +255,21 @@ return ret; } - (size_t)writeCString: (const char*)str { - if (sock < 0) { - /* FIXME: Throw exception */ - return 0; - } + if (sock < 0) + @throw [OFNotConnectedException newWithObject: self]; return [self writeNBytes: strlen(str) fromBuffer: (const uint8_t*)str]; } - close { - if (sock < 0) { - /* FIXME: Throw exception */ - return nil; - } + if (sock < 0) + @throw [OFNotConnectedException newWithObject: self]; sock = -1; if (saddr != NULL) [self freeMem: saddr];