2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-11-29 22:26:34 +00:00
|
|
|
// THIS FILE IS DEPRECATED.
|
|
|
|
// ITS ORIGINAL PURPOSE WAS TO TEST THE FILE XFER LAYER IN ISOLATION,
|
|
|
|
// BUT THIS IS NO LONGER POSSIBLE
|
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "cpp.h"
|
2002-07-22 23:07:14 +00:00
|
|
|
|
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
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_6a5fc6c730 = "$Id$";
|