From: Pekka Riikonen Date: Sun, 24 Jun 2001 09:38:22 +0000 (+0000) Subject: updates. X-Git-Tag: robodoc-323~147 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=377ac1cec4ace380054fd234babb6eefeab04a91 updates. --- diff --git a/lib/silcutil/silcsockconn.h b/lib/silcutil/silcsockconn.h index d3a95c67..c265bfb8 100644 --- a/lib/silcutil/silcsockconn.h +++ b/lib/silcutil/silcsockconn.h @@ -6,9 +6,9 @@ * * COPYRIGHT * - * Author: Pekka Riikonen + * Author: Pekka Riikonen * - * Copyright (C) 1997 - 2000 Pekka Riikonen + * Copyright (C) 1997 - 2001 Pekka Riikonen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/lib/silcutil/unix/silcunixsockconn.c b/lib/silcutil/unix/silcunixsockconn.c index 8932d0cd..acd8cb5e 100644 --- a/lib/silcutil/unix/silcunixsockconn.c +++ b/lib/silcutil/unix/silcunixsockconn.c @@ -2,9 +2,9 @@ silcunixsockconn.c - Author: Pekka Riikonen + Author: Pekka Riikonen - Copyright (C) 1997 - 2000 Pekka Riikonen + Copyright (C) 1997 - 2001 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/lib/silcutil/win32/silcwin32net.c b/lib/silcutil/win32/silcwin32net.c index d3ff0474..e34d981a 100644 --- a/lib/silcutil/win32/silcwin32net.c +++ b/lib/silcutil/win32/silcwin32net.c @@ -156,10 +156,54 @@ int silc_net_create_connection(int port, char *host) int silc_net_create_connection_async(int port, char *host) { + SOCKET sock; + int rval, err; + struct hostent *dest; + struct sockaddr_in desthost; + SILC_LOG_DEBUG(("Creating connection (async) to host %s port %d", host, port)); - return silc_net_create_connection(port, host); + /* Do host lookup */ + dest = gethostbyname(host); + if (!dest) { + SILC_LOG_ERROR(("Network (%s) unreachable", host)); + return -1; + } + + /* Set socket information */ + memset(&desthost, 0, sizeof(desthost)); + desthost.sin_port = htons(port); + desthost.sin_family = AF_INET; + memcpy(&desthost.sin_addr, dest->h_addr_list[0], sizeof(desthost.sin_addr)); + + /* Create the connection socket */ + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock == INVALID_SOCKET) { + SILC_LOG_ERROR(("Cannot create socket")); + return -1; + } + + /* Set socket to nonblocking mode */ + silc_net_set_socket_nonblock(sock); + + /* Connect to the host */ + rval = connect(sock, (struct sockaddr *)&desthost, sizeof(desthost)); + err = WSAGetLastError(); + if (rval == SOCKET_ERROR && err != WSAEWOULDBLOCK) { + SILC_LOG_ERROR(("Cannot connect to remote host")); + shutdown(sock, 2); + closesocket(sock); + return -1; + } + + /* Set appropriate options */ + silc_net_set_socket_opt(sock, IPPROTO_TCP, TCP_NODELAY, 1); + silc_net_set_socket_opt(sock, SOL_SOCKET, SO_KEEPALIVE, 1); + + SILC_LOG_DEBUG(("Connection created")); + + return sock; } /* Closes the connection by closing the socket connection. */ @@ -191,5 +235,6 @@ bool silc_net_addr2bin(const char *addr, unsigned char *bin, int silc_net_set_socket_nonblock(int sock) { - return 0; + unsigned long on = 1; + return ioctlsocket(sock, FIONBIO, &on); } diff --git a/lib/silcutil/win32/silcwin32schedule.c b/lib/silcutil/win32/silcwin32schedule.c index e0f18a0b..d87681db 100644 --- a/lib/silcutil/win32/silcwin32schedule.c +++ b/lib/silcutil/win32/silcwin32schedule.c @@ -21,7 +21,19 @@ #include "silcincludes.h" -/* XXX Untested! */ +/* XXX This probably does not work at all the way we want. We mostly + need the scheduler to handle socket connections. The MSDN says the + WaitForMultipleObjects should not be used for sockets. Instead they + should be handled through windows messages (Like WSAAsyncSelect) but + that would require some different approach to this whole thing. Also, + I don't know whether I could use the Winsock's select()?? Maybe it would + be possible to use select(), WaitForMultipleObjects and handle the + windows messages with the PeekMessage() etc... Dunno... Someone who + knows these things should take a look at this. Also, If it requires + some more tweaking I can abandon this silc_select() thingy all together + and move the generic code to unix/ and program the SILC Scheduler + interface all together as platform specific. It is here just to + use as match common code as possible... -Pekka */ /* Our "select()" for WIN32. This actually is not the select() and does not call Winsock's select() (since it cannot be used for our purposes)