- Refactor and fix connection opening.

- Target test.winehq.org.
oldstable
Ferenc Wagner 2004-03-19 19:15:23 +00:00 committed by Alexandre Julliard
parent 5983223b70
commit ca0f5793da
2 changed files with 27 additions and 25 deletions

View File

@ -33,25 +33,29 @@ open_http (const char *server)
report (R_STATUS, "Opening HTTP connection to %s", server); report (R_STATUS, "Opening HTTP connection to %s", server);
if (WSAStartup (MAKEWORD (2,2), &wsad)) return INVALID_SOCKET; if (WSAStartup (MAKEWORD (2,2), &wsad)) return INVALID_SOCKET;
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s != INVALID_SOCKET) {
unsigned long addr = inet_addr(server);
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_port = htons (80); sa.sin_port = htons (80);
if (addr != INADDR_NONE) sa.sin_addr.s_addr = inet_addr (server);
sa.sin_addr.s_addr = addr; if (sa.sin_addr.s_addr == INADDR_NONE) {
else struct hostent *host = gethostbyname (server);
{ if (!host) {
struct hostent *host; report (R_ERROR, "Hostname lookup failed for %s", server);
goto failure;
if ((host = gethostbyname(server)) != NULL)
addr = ((struct in_addr *)host->h_addr)->s_addr;
} }
if (!connect (s, (struct sockaddr*)&sa, sa.sin_addr.s_addr = ((struct in_addr *)host->h_addr)->s_addr;
sizeof (struct sockaddr_in))) }
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == INVALID_SOCKET) {
report (R_ERROR, "Can't open network socket: %d",
WSAGetLastError ());
goto failure;
}
if (!connect (s, (struct sockaddr*)&sa, sizeof (struct sockaddr_in)))
return s; return s;
}
report (R_ERROR, "Can't connect: %d", WSAGetLastError ());
closesocket (s);
failure:
WSACleanup (); WSACleanup ();
return INVALID_SOCKET; return INVALID_SOCKET;
} }
@ -110,7 +114,7 @@ send_file (const char *name)
/* RFC 2068 */ /* RFC 2068 */
#define SEP "-" #define SEP "-"
const char head[] = "POST /submit HTTP/1.0\r\n" const char head[] = "POST /submit HTTP/1.0\r\n"
"Host: afavant\r\n" "Host: test.winehq.org\r\n"
"User-Agent: Winetest Shell\r\n" "User-Agent: Winetest Shell\r\n"
"Content-Type: multipart/form-data; boundary=" SEP "\r\n" "Content-Type: multipart/form-data; boundary=" SEP "\r\n"
"Content-Length: %u\r\n\r\n"; "Content-Length: %u\r\n\r\n";
@ -123,12 +127,8 @@ send_file (const char *name)
"--" SEP "--\r\n"; "--" SEP "--\r\n";
buffer = xmalloc (BUFLEN + 1); buffer = xmalloc (BUFLEN + 1);
s = open_http ("www.winehq.org"); s = open_http ("test.winehq.org");
if (s == INVALID_SOCKET) { if (s == INVALID_SOCKET) return 1;
report (R_WARNING, "Can't open network connection: %d",
WSAGetLastError ());
return 1;
}
f = fopen (name, "rb"); f = fopen (name, "rb");
if (!f) { if (!f) {

View File

@ -19,6 +19,7 @@
* *
*/ */
#include <windows.h> #include <windows.h>
#include <errno.h>
#include "winetest.h" #include "winetest.h"
@ -43,7 +44,8 @@ void xprintf (const char *fmt, ...)
va_list ap; va_list ap;
va_start (ap, fmt); va_start (ap, fmt);
if (vprintf (fmt, ap) < 0) report (R_FATAL, "Can't write logs."); if (vprintf (fmt, ap) < 0)
report (R_FATAL, "Can't write logs: %d", errno);
va_end (ap); va_end (ap);
} }