1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
|
|
1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
while (rnd < 1024)
rnd = (uint16_t)rand();
OFSocketAddressSetPort(address, rnd);
if ((ret = bind(_socket, &address->sockaddr.sockaddr,
address->length)) == 0) {
port = rnd;
break;
}
if (OFSocketErrNo() != EADDRINUSE) {
int errNo = OFSocketErrNo();
OFString *host = OFSocketAddressString(address);
uint16_t port = OFSocketAddressPort(port);
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException
exceptionWithHost: host
port: port
|
|
<
<
|
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
while (rnd < 1024)
rnd = (uint16_t)rand();
OFSocketAddressSetPort(address, rnd);
if ((ret = bind(_socket, &address->sockaddr.sockaddr,
address->length)) == 0)
break;
if (OFSocketErrNo() != EADDRINUSE) {
int errNo = OFSocketErrNo();
OFString *host = OFSocketAddressString(address);
port = OFSocketAddressPort(address);
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindFailedException
exceptionWithHost: host
port: port
|