* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: socket.c,v 1.30.18.36 2008/09/11 06:39:02 marka Exp $ */
+/* $Id: socket.c,v 1.30.18.37 2008/09/11 07:01:46 marka Exp $ */
/* This code uses functions which are only available on Server 2003 and
* higher, and Windows XP and higher.
* Used value-result for recvmsg, value only for sendmsg.
*/
struct msghdr {
- SOCKADDR to_addr; /* UDP send/recv address */
+ SOCKADDR_STORAGE to_addr; /* UDP send/recv address */
int to_addr_len; /* length of the address */
- WSABUF *msg_iov; /* scatter/gather array */
- u_int msg_iovlen; /* # elements in msg_iov */
- void *msg_control; /* ancillary data, see below */
- u_int msg_controllen; /* ancillary data buffer len */
+ WSABUF *msg_iov; /* scatter/gather array */
+ u_int msg_iovlen; /* # elements in msg_iov */
+ void *msg_control; /* ancillary data, see below */
+ u_int msg_controllen; /* ancillary data buffer len */
int msg_totallen; /* total length of this message */
} msghdr;
-
+
/*
* The size to raise the receive buffer to.
*/
* calls. It also allows us to read-ahead in some cases.
*/
struct {
- SOCKADDR from_addr; // UDP send/recv address
+ SOCKADDR_STORAGE from_addr; // UDP send/recv address
int from_addr_len; // length of the address
char *base; // the base of the buffer
char *consume_position; // where to start copying data from next
connected : 1,
pending_connect : 1, /* connect pending */
bound : 1; /* bound to local addr */
-
- unsigned int pending_iocp; /* Should equal the counters below. Debug. */
+ unsigned int pending_iocp; /* Should equal the counters below. Debug. */
unsigned int pending_recv; /* Number of outstanding recv() calls. */
unsigned int pending_send; /* Number of outstanding send() calls. */
unsigned int pending_accept; /* Number of outstanding accept() calls. */
/*
* Worker threads for servicing the I/O
- */
+ */
iocompletionport_createthreads(manager->maxIOCPThreads, manager);
}
void
InitSockets(void) {
RUNTIME_CHECK(isc_once_do(&initialise_once,
- initialise) == ISC_R_SUCCESS);
+ initialise) == ISC_R_SUCCESS);
if (!initialised)
exit(1);
}
*Error = 0;
Result = WSASendTo(sock->fd, messagehdr->msg_iov,
messagehdr->msg_iovlen, &BytesSent,
- Flags, &messagehdr->to_addr,
+ Flags, (SOCKADDR *)&messagehdr->to_addr,
messagehdr->to_addr_len, (LPWSAOVERLAPPED)lpo,
NULL);
Error = 0;
Result = WSARecvFrom((SOCKET)sock->fd, iov, 1,
&NumBytes, &Flags,
- &sock->recvbuf.from_addr,
+ (SOCKADDR *)&sock->recvbuf.from_addr,
&sock->recvbuf.from_addr_len,
(LPWSAOVERLAPPED)lpo, NULL);
break;
default:
- isc_result = isc__errno2result(Result);
+ isc_result = isc__errno2result(Error);
if (isc_result == ISC_R_UNEXPECTED)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"WSARecvFrom: Windows error code: %d, isc result %d",
set_dev_address(isc_sockaddr_t *address, isc_socket_t *sock,
isc_socketevent_t *dev)
{
- if (address != NULL)
- dev->address = *address;
- else
+ if (sock->type == isc_sockettype_udp) {
+ if (address != NULL)
+ dev->address = *address;
+ else
+ dev->address = sock->address;
+ } else if (sock->type == isc_sockettype_tcp) {
+ INSIST(address == NULL);
dev->address = sock->address;
+ }
}
static void
isc_socket_newconnev_t *adev;
isc_result_t result = ISC_R_SUCCESS;
isc_socket_t *nsock;
- struct sockaddr_in *localaddr;
+ struct sockaddr *localaddr;
int localaddr_len = sizeof(*localaddr);
- struct sockaddr_in *remoteaddr;
+ struct sockaddr *remoteaddr;
int remoteaddr_len = sizeof(*remoteaddr);
INSIST(VALID_SOCKET(sock));
* and return the new socket.
*/
ISCGetAcceptExSockaddrs(lpo->acceptbuffer, 0,
- sizeof(SOCKADDR) + 16, sizeof(SOCKADDR) + 16,
+ sizeof(SOCKADDR_STORAGE) + 16, sizeof(SOCKADDR_STORAGE) + 16,
(LPSOCKADDR *)&localaddr, &localaddr_len,
(LPSOCKADDR *)&remoteaddr, &remoteaddr_len);
memcpy(&adev->address.type, remoteaddr, remoteaddr_len);
isc_result_t
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr,
- unsigned int options) {
+ unsigned int options) {
int bind_errno;
char strbuf[ISC_STRERRORSIZE];
int on = 1;
sizeof(IoCompletionInfo));
RUNTIME_CHECK(lpo != NULL);
lpo->acceptbuffer = (void *)HeapAlloc(hHeapHandle, HEAP_ZERO_MEMORY,
- (sizeof(SOCKADDR) + 16) * 2);
+ (sizeof(SOCKADDR_STORAGE) + 16) * 2);
RUNTIME_CHECK(lpo->acceptbuffer != NULL);
lpo->adev = adev;
nsock->fd, /* Accepted Socket */
lpo->acceptbuffer, /* Buffer for initial Recv */
0, /* Length of Buffer */
- sizeof(SOCKADDR) + 16, /* Local address length + 16 */
- sizeof(SOCKADDR) + 16, /* Remote address lengh + 16 */
+ sizeof(SOCKADDR_STORAGE) + 16, /* Local address length + 16 */
+ sizeof(SOCKADDR_STORAGE) + 16, /* Remote address lengh + 16 */
(LPDWORD)&lpo->received_bytes, /* Bytes Recved */
(LPOVERLAPPED)lpo /* Overlapped structure */
);