2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-07-22 23:07:14 +00:00
|
|
|
#include "windows_cpp.h"
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
2002-07-22 23:07:14 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "winsock.h"
|
|
|
|
#include "win_net.h"
|
|
|
|
#endif
|
|
|
|
#if HAVE_UNISTD_H
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <unistd.h>
|
2002-07-22 23:07:14 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "http.h"
|
|
|
|
#include "net_xfer.h"
|
2002-06-06 22:49:07 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#define UNCONNECTED 0
|
|
|
|
#define WRITE_WAIT 1
|
|
|
|
#define HEADER_WAIT 2
|
|
|
|
#define BODY_WAIT 3
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
NET_XFER_SET nxs;
|
|
|
|
NET_XFER* nxp;
|
|
|
|
HTTP_REPLY_HEADER reply_header;
|
|
|
|
int n;
|
|
|
|
|
2002-07-22 23:07:14 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
NetOpen();
|
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
nxp = new NET_XFER;
|
|
|
|
nxp->init("localhost.localdomain", 80, 1024);
|
|
|
|
nxp->net_xfer_state = UNCONNECTED;
|
|
|
|
nxs.insert(nxp);
|
|
|
|
|
|
|
|
char* buf = "GET /my_index.html HTTP/1.0\015\012"
|
|
|
|
"Host: localhost.localdomain:80\015\012"
|
|
|
|
"Accept: */*\015\012"
|
|
|
|
"\015\012";
|
|
|
|
|
|
|
|
while (1) {
|
2003-02-26 00:47:57 +00:00
|
|
|
nxs.poll();
|
2002-04-30 22:22:54 +00:00
|
|
|
switch(nxp->net_xfer_state) {
|
|
|
|
case UNCONNECTED:
|
|
|
|
if(nxp->is_connected) {
|
|
|
|
nxp->net_xfer_state = WRITE_WAIT;
|
|
|
|
nxp->want_upload = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WRITE_WAIT:
|
|
|
|
if (nxp->io_ready) {
|
2002-07-22 23:07:14 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
n = send(nxp->socket, buf, strlen(buf), 0);
|
|
|
|
#else
|
2002-04-30 22:22:54 +00:00
|
|
|
n = write(nxp->socket, buf, strlen(buf));
|
2002-07-22 23:07:14 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
printf("wrote %d bytes\n", n);
|
|
|
|
nxp->net_xfer_state = HEADER_WAIT;
|
|
|
|
nxp->want_upload = false;
|
|
|
|
nxp->want_download = true;
|
|
|
|
nxp->io_ready = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HEADER_WAIT:
|
|
|
|
if (nxp->io_ready) {
|
|
|
|
read_http_reply_header(nxp->socket, reply_header);
|
|
|
|
nxp->net_xfer_state = BODY_WAIT;
|
2002-07-22 23:07:14 +00:00
|
|
|
nxp->file = fopen("foo", "wb");
|
2002-04-30 22:22:54 +00:00
|
|
|
nxp->do_file_io = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BODY_WAIT:
|
|
|
|
if (nxp->io_done) break;
|
|
|
|
}
|
|
|
|
if (nxp->io_done) break;
|
2003-03-11 22:18:01 +00:00
|
|
|
boinc_sleep(1.);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
nxs.remove(nxp);
|
2002-10-24 16:54:31 +00:00
|
|
|
if (nxp->file) {
|
|
|
|
fclose(nxp->file);
|
|
|
|
}
|
2002-07-22 23:07:14 +00:00
|
|
|
|
|
|
|
return 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|