Mercurial > pidgin.yaz
diff src/protocols/oscar/conn.c @ 3630:9682c0e022c6
[gaim-migrate @ 3753]
Yeah this will probably break a lot of shit knowing my luck. But hey, I really don't care what people thnk.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Fri, 11 Oct 2002 03:14:01 +0000 |
parents | 26de71e80b49 |
children | e941bfbacf7c |
line wrap: on
line diff
--- a/src/protocols/oscar/conn.c Fri Oct 11 02:10:08 2002 +0000 +++ b/src/protocols/oscar/conn.c Fri Oct 11 03:14:01 2002 +0000 @@ -14,6 +14,8 @@ #include <netdb.h> #include <sys/socket.h> #include <netinet/in.h> +#else +#include <winsock.h> #endif /* @@ -317,7 +319,11 @@ { if (deadconn->fd >= 3) +#ifndef _WIN32 close(deadconn->fd); +#else + closesocket(deadconn->fd); +#endif deadconn->fd = -1; if (deadconn->handlerlist) aim_clearhandlers(deadconn); @@ -429,7 +435,11 @@ fd = socket(hp->h_addrtype, SOCK_STREAM, 0); if (connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) { faimdprintf(sess, 0, "proxyconnect: unable to connect to proxy\n"); +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } @@ -445,22 +455,40 @@ buf[2] = 0x00; i = 3; } - +#ifndef _WIN32 if (write(fd, buf, i) < i) { +#else + if (send(fd, buf, i, 0) < i) { +#endif *statusret = errno; +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } - +#ifndef _WIN32 if (read(fd, buf, 2) < 2) { +#else + if (recv(fd, buf, 2, 0) < 2) { +#endif *statusret = errno; +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } if ((buf[0] != 0x05) || (buf[1] == 0xff)) { *statusret = EINVAL; +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } @@ -471,19 +499,39 @@ i += aimutil_putstr(buf+i, sess->socksproxy.username, strlen(sess->socksproxy.username)); i += aimutil_put8(buf+i, strlen(sess->socksproxy.password)); i += aimutil_putstr(buf+i, sess->socksproxy.password, strlen(sess->socksproxy.password)); +#ifndef _WIN32 if (write(fd, buf, i) < i) { +#else + if (send(fd, buf, i, 0) < i) { +#endif *statusret = errno; +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } +#ifndef _WIN32 if (read(fd, buf, 2) < 2) { +#else + if (recv(fd, buf, 2, 0) < 2) { +#endif *statusret = errno; +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } if ((buf[0] != 0x01) || (buf[1] != 0x00)) { *statusret = EINVAL; +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } } @@ -495,27 +543,49 @@ i += aimutil_put8(buf+i, strlen(host)); i += aimutil_putstr(buf+i, host, strlen(host)); i += aimutil_put16(buf+i, port); - +#ifndef _WIN32 if (write(fd, buf, i) < i) { +#else + if (send(fd, buf, i, 0) < i) { +#endif *statusret = errno; +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } +#ifndef _WIN32 if (read(fd, buf, 10) < 10) { +#else + if (recv(fd, buf, 10, 0) < 10) { +#endif *statusret = errno; +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } if ((buf[0] != 0x05) || (buf[1] != 0x00)) { *statusret = EINVAL; +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif return -1; } } else { /* connecting directly */ struct sockaddr_in sa; struct hostent *hp; - +#ifdef _WIN32 + int imode = 1; + int w_errno = 0; +#endif if (!(hp = gethostbyname(host))) { *statusret = (h_errno | AIM_CONN_STATUS_RESOLVERR); return -1; @@ -529,17 +599,29 @@ fd = socket(hp->h_addrtype, SOCK_STREAM, 0); if (sess->flags & AIM_SESS_FLAGS_NONBLOCKCONNECT) +#ifndef _WIN32 fcntl(fd, F_SETFL, O_NONBLOCK); /* XXX save flags */ - +#else + ioctlsocket(fd, FIONBIO, (unsigned long *)&imode); +#endif if (connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) { if (sess->flags & AIM_SESS_FLAGS_NONBLOCKCONNECT) { +#ifndef _WIN32 if ((errno == EINPROGRESS) || (errno == EINTR)) { +#else + w_errno = WSAGetLastError(); + if ((w_errno == WSAEINPROGRESS) || (w_errno == WSAEINTR)) { +#endif if (statusret) *statusret |= AIM_CONN_STATUS_INPROGRESS; return fd; } } +#ifndef _WIN32 close(fd); +#else + closesocket(fd); +#endif fd = -1; } } @@ -987,7 +1069,12 @@ { fd_set fds, wfds; struct timeval tv; - int res, error = ETIMEDOUT; + int res; +#ifndef _WIN32 + int error = ETIMEDOUT; +#else + int error = 0; +#endif aim_rxcallback_t userfunc; if (!conn || (conn->fd == -1)) @@ -1004,7 +1091,11 @@ tv.tv_usec = 0; if ((res = select(conn->fd+1, &fds, &wfds, NULL, &tv)) == -1) { +#ifndef _WIN32 error = errno; +#else + error = WSAGetLastError(); +#endif aim_conn_close(conn); errno = error; return -1; @@ -1015,9 +1106,13 @@ if (FD_ISSET(conn->fd, &fds) || FD_ISSET(conn->fd, &wfds)) { int len = sizeof(error); - +#ifndef _WIN32 if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) error = errno; +#else + if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, (char*)&error, &len) < 0) + error = WSAGetLastError(); +#endif } if (error) { @@ -1025,9 +1120,9 @@ errno = error; return -1; } - +#ifndef _WIN32 fcntl(conn->fd, F_SETFL, 0); /* XXX should restore original flags */ - +#endif conn->status &= ~AIM_CONN_STATUS_INPROGRESS; if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE)))