1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * The contents of this file are subject to the Mozilla Public License
9 * Version 1.0 (the "License"); you may not use this file except in
10 * compliance with the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS"
14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15 * License for the specific language governing rights and limitations
18 * The Original Code is Curl.
20 * The Initial Developer of the Original Code is Daniel Stenberg.
22 * Portions created by the Initial Developer are Copyright (C) 1998.
23 * All Rights Reserved.
25 * ------------------------------------------------------------
27 * - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
31 * $Source: /cvsroot/curl/curl/lib/Attic/upload.c,v $
33 * $Date: 1999-12-29 14:21:39 $
38 * ------------------------------------------------------------
39 ****************************************************************************/
45 #ifdef HAVE_SYS_SELECT_H
46 #include <sys/select.h>
49 #if !defined(__GNUC__) || defined(__MINGW32__)
52 #include <time.h> /* for the time_t typedef! */
54 #if defined(__GNUC__) && defined(TIME_WITH_SYS_TIME)
60 #include <curl/curl.h>
63 #include <net/socket.h>
67 #include "speedcheck.h"
71 /* --- upload a stream to a socket --- */
73 UrgError
Upload(struct UrlData
*data
,
79 struct timeval interval
;
81 char *buf
= data
->buffer
;
87 char scratch
[BUFSIZE
* 2];
90 /* timeout every X second
91 - makes a better progressmeter (i.e even when no data is sent, the
92 meter can be updated and reflect reality)
93 - allows removal of the alarm() crap
94 - variable timeout is easier
97 myalarm(0); /* switch off the alarm-style timeout */
102 FD_ZERO(&writefd
); /* clear it */
103 FD_SET(sockfd
, &writefd
);
108 size_t bytes_written
= 0;
110 writefd
= keepfd
; /* set this every lap in the loop */
112 interval
.tv_usec
= 0;
114 switch(select(sockfd
+1, NULL
, &writefd
, NULL
, &interval
)) {
115 case -1: /* error, stop writing */
118 case 0: /* timeout */
120 default: /* write! */
122 buf
= data
->buffer
; /* put it back on the buffer */
124 nread
= data
->fread(buf
, 1, BUFSIZE
, data
->in
);
133 /* convert LF to CRLF if so asked */
135 for(i
= 0, si
= 0; i
< (int)nread
; i
++, si
++) {
136 if (buf
[i
] == 0x0a) {
137 scratch
[si
++] = 0x0d;
141 scratch
[si
] = buf
[i
];
145 buf
= scratch
; /* point to the new buffer */
148 /* write to socket */
150 bytes_written
= swrite(sockfd
, buf
, nread
);
153 bytes_written
= SSL_write(data
->ssl
, buf
, nread
);
155 bytes_written
= swrite(sockfd
, buf
, nread
);
157 #endif /* USE_SSLEAY */
158 if(nread
!= bytes_written
) {
159 failf(data
, "Failed uploading file");
160 return URG_FTP_WRITE_ERROR
;
164 ProgressShow(data
, bytecount
, start
, now
, FALSE
);
165 urg
=speedcheck(data
, now
);
168 if(data
->timeout
&& (tvdiff(now
,start
)>data
->timeout
)) {
169 failf(data
, "Upload timed out with %d bytes sent", bytecount
);
170 return URG_OPERATION_TIMEOUTED
;
174 ProgressShow(data
, bytecount
, start
, now
, TRUE
);
175 *bytecountp
= bytecount
;