Re: Cancellation for GnomeVFSInetConnecton



On Tue, 2004-03-30 at 16:06, Christian Kellner wrote:
> Hi,
> 
> I created a patch wich adds cancellation for GnomeVFSInetConnection. I
> Also moved the wrapper for setting flags on file descriptors from gnome-
> job to gnome-vfs-private-utils.
> Please have a look at it and tell me what you think.

I commited the flag setting stuff with two changes:

+/* This has been moved here from gnome-vfs-job.c because it is needed in other
+   places too */

We generally try to avoid having history like this in the code. They
tend to bitrot and become huge comments with no bearing on the current
code.  

+ * Since: 2.6

2.7 now :)


The cancellation/non-blocking part needed more work. The rest on
gnome-vfs needs to handle the fact that the fds can be non-blocking.
Also, we can't keep around the cancellation passed in on create. We need
to pass a cancellation to each socket operation. Also, the cancellation
can be NULL.

+                       if (FD_ISSET (connection->sock, &read_fds)) {
+                               goto read_loop;
+                       }
+
+                       if (FD_ISSET (connection->pipe_cancel, &read_fds)) {
+                               return GNOME_VFS_ERROR_CANCELLED;
+                       }
+               }

Need to check the cancellation fd first.

I finished the work on the patch (attached), and it seems to work. Could
you take a look at it and see if it looks right, and test the
cancellation stuff. I've just tested this with nautilus, and it seems to
work ok.

Also, maybe we should add some sort of timeout to the socket calls.
Picking a timeout that is short enought to be useful and never times out
on valid calls is hard of course...



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's an uncontrollable white trash card sharp searching for his wife's true 
killer. She's an artistic renegade college professor operating on the wrong 
side of the law. They fight crime! 
? GNOME_VFS_Daemon.idl
? a
? alexl master gnome org
? am.patch
? b
? build
? configure.in.diff-PKG_CHECK_MODULES
? daemon-merge.patch
? duplicated.diff
? ftp-buffer.patch
? gnome-vfs-2.5.4.1.tar.gz
? gnome-vfs-2.5.4.tar.gz
? gnome-vfs-2.5.6.tar.gz
? gnome-vfs-2.5.7.tar.gz
? gnome-vfs-2.5.8.tar.gz
? gnome-vfs-2.5.90.tar.gz
? gnome-vfs-2.5.91.tar.gz
? gnome-vfs-2.6.0
? gnome-vfs-2.6.0.tar.gz
? gnome-vfs-build.patch
? gnome-vfs-doc5.diff
? gnome-vfs-fadvice.patch
? gnome-vfs-ioctl.patch
? gnome-vfs-monitor-crash.patch
? gnome-vfs-text-sniff.patch
? gnome-vfs.patch.4
? gvfs-http-handleinfo.patch
? intltool-modules
? merge2.
? merge2.patch
? noblocking-cancellation.patch
? open_as_channel.patch
? proxy.patch
? revert
? review-cancellation
? showattachment.cgi?attach_id=15172
? showattachment.cgi?attach_id=15391
? showattachment.cgi?attach_id=15430
? showattachment.cgi?attach_id=16660
? showattachment.cgi?attach_id=19166
? showattachment.cgi?attach_id=19538
? showattachment.cgi?attach_id=20163
? showattachment.cgi?attach_id=23560
? showattachment.cgi?attach_id=24907
? smb-permissions.patch
? smb-write.patch
? subdir_fix.patch
? trash-fix.patch
? daemon/a
? daemon/spx2_panther_expose.mov
? daemon/vfs-daemon
? doc/deprecated
? doc/gnome-vfs-decl-list.txt
? doc/gnome-vfs-decl.txt
? doc/gnome-vfs-undocumented.txt
? doc/gnome-vfs.args
? doc/gnome-vfs.hierarchy
? doc/gnome-vfs.signals
? doc/xml
? doc/tmpl/gnome-vfs-2.0-unused.sgml
? doc/tmpl/gnome-vfs-unused.sgml
? doc/tmpl/gnome-vfs.sgml
? libgnomevfs/a
? libgnomevfs/gnome-vfs-enum-types.c
? libgnomevfs/gnome-vfs-enum-types.h
? libgnomevfs/gnome-vfs-mime-info.c.setvbuf
? libgnomevfs/gnome-vfs-mime.c.setvbuf
? libgnomevfs/s-enum-types-c
? libgnomevfs/s-enum-types-h
? libgnomevfs/showattachment.cgi?attach_id=24358
? libgnomevfs/spew.patch
? libgnomevfs/start_of_non_blocking.patch
? libgnomevfs/xdgmime_utf8.patch
? man/Makefile
? man/Makefile.in
? man/gnome-vfs-mime.5
? modules/a
? modules/applications.vfolder-info
? modules/core.29279
? modules/preferences.vfolder-info
? modules/programs.vfolder-info
? po/a
? programs/a
? test/1
? test/a
? test/lgo
? test/log
? test/log2
? test/log3
? test/test-metadata
? test/test.txt
? test/test_monitor_overflow.patch
? test/vfs-test.out
Index: doc/tmpl/gnome-vfs-socket-buffer.sgml
===================================================================
RCS file: /cvs/gnome/gnome-vfs/doc/tmpl/gnome-vfs-socket-buffer.sgml,v
retrieving revision 1.2
diff -u -p -r1.2 gnome-vfs-socket-buffer.sgml
--- doc/tmpl/gnome-vfs-socket-buffer.sgml	16 Jun 2002 23:43:33 -0000	1.2
+++ doc/tmpl/gnome-vfs-socket-buffer.sgml	1 Apr 2004 13:23:55 -0000
@@ -30,6 +30,7 @@ gnome-vfs-socket-buffer
 
 @socket_buffer: 
 @close_socket: 
+ cancellation: 
 @Returns: 
 
 
@@ -42,6 +43,7 @@ gnome-vfs-socket-buffer
 @buffer: 
 @bytes: 
 @bytes_read: 
+ cancellation: 
 @Returns: 
 
 
@@ -52,6 +54,7 @@ gnome-vfs-socket-buffer
 
 @socket_buffer: 
 @character: 
+ cancellation: 
 @Returns: 
 
 
@@ -64,6 +67,7 @@ gnome-vfs-socket-buffer
 @buffer: 
 @bytes: 
 @bytes_written: 
+ cancellation: 
 @Returns: 
 
 
@@ -73,6 +77,7 @@ gnome-vfs-socket-buffer
 </para>
 
 @socket_buffer: 
+ cancellation: 
 @Returns: 
 <!-- # Unused Parameters # -->
 @buffer: 
Index: doc/tmpl/gnome-vfs-socket.sgml
===================================================================
RCS file: /cvs/gnome/gnome-vfs/doc/tmpl/gnome-vfs-socket.sgml,v
retrieving revision 1.2
diff -u -p -r1.2 gnome-vfs-socket.sgml
--- doc/tmpl/gnome-vfs-socket.sgml	15 Nov 2003 14:55:51 -0000	1.2
+++ doc/tmpl/gnome-vfs-socket.sgml	1 Apr 2004 13:23:55 -0000
@@ -23,6 +23,7 @@ gnome-vfs-socket
 @buffer: 
 @bytes: 
 @bytes_read: 
+ cancellation: 
 @Returns: 
 
 
@@ -35,6 +36,7 @@ gnome-vfs-socket
 @buffer: 
 @bytes: 
 @bytes_written: 
+ cancellation: 
 @Returns: 
 
 
@@ -44,6 +46,7 @@ gnome-vfs-socket
 </para>
 
 @connection: 
+ cancellation: 
 
 
 <!-- ##### STRUCT GnomeVFSSocketImpl ##### -->
@@ -74,6 +77,7 @@ gnome-vfs-socket
 @buffer: 
 @bytes: 
 @bytes_written: 
+ cancellation: 
 @Returns: 
 
 
@@ -83,6 +87,7 @@ gnome-vfs-socket
 </para>
 
 @socket: 
+ cancellation: 
 @Returns: 
 
 
@@ -95,6 +100,7 @@ gnome-vfs-socket
 @buffer: 
 @bytes: 
 @bytes_read: 
+ cancellation: 
 @Returns: 
 
 
Index: doc/tmpl/gnome-vfs-ssl.sgml
===================================================================
RCS file: /cvs/gnome/gnome-vfs/doc/tmpl/gnome-vfs-ssl.sgml,v
retrieving revision 1.1
diff -u -p -r1.1 gnome-vfs-ssl.sgml
--- doc/tmpl/gnome-vfs-ssl.sgml	16 Jun 2002 10:05:53 -0000	1.1
+++ doc/tmpl/gnome-vfs-ssl.sgml	1 Apr 2004 13:23:55 -0000
@@ -30,6 +30,7 @@ gnome-vfs-ssl
 @handle_return: 
 @host: 
 @port: 
+ cancellation: 
 @Returns: 
 
 
@@ -40,6 +41,7 @@ gnome-vfs-ssl
 
 @handle_return: 
 @fd: 
+ cancellation: 
 @Returns: 
 
 
@@ -52,6 +54,7 @@ gnome-vfs-ssl
 @buffer: 
 @bytes: 
 @bytes_read: 
+ cancellation: 
 @Returns: 
 
 
@@ -64,6 +67,7 @@ gnome-vfs-ssl
 @buffer: 
 @bytes: 
 @bytes_written: 
+ cancellation: 
 @Returns: 
 
 
@@ -73,6 +77,7 @@ gnome-vfs-ssl
 </para>
 
 @ssl: 
+ cancellation: 
 
 
 <!-- ##### FUNCTION gnome_vfs_ssl_to_socket ##### -->
Index: libgnomevfs/gnome-vfs-inet-connection.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-inet-connection.c,v
retrieving revision 1.13
diff -u -p -r1.13 gnome-vfs-inet-connection.c
--- libgnomevfs/gnome-vfs-inet-connection.c	22 Jan 2004 12:29:09 -0000	1.13
+++ libgnomevfs/gnome-vfs-inet-connection.c	1 Apr 2004 13:23:55 -0000
@@ -35,6 +35,8 @@
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/select.h>
+#include <fcntl.h>
 #include <unistd.h>
 
 /* AIX #defines h_errno */
@@ -185,6 +187,9 @@ gnome_vfs_inet_connection_create (GnomeV
 		new->sock = sock;
 
 	}
+
+	_gnome_vfs_set_fd_flags (new->sock, O_NONBLOCK);
+
 	*connection_return = new;
 	return GNOME_VFS_OK;
 }
@@ -214,9 +219,10 @@ gnome_vfs_inet_connection_destroy (Gnome
  * Closes @connection, freeing all used resources.
  **/
 static void
-gnome_vfs_inet_connection_close (GnomeVFSInetConnection *connection)
+gnome_vfs_inet_connection_close (GnomeVFSInetConnection *connection,
+				 GnomeVFSCancellation *cancellation)
 {
-	gnome_vfs_inet_connection_destroy (connection, NULL);
+	gnome_vfs_inet_connection_destroy (connection, cancellation);
 }
 
 /**
@@ -252,22 +258,63 @@ static GnomeVFSResult 
 gnome_vfs_inet_connection_read (GnomeVFSInetConnection *connection,
 		                gpointer buffer,
 		                GnomeVFSFileSize bytes,
-		                GnomeVFSFileSize *bytes_read)
+		                GnomeVFSFileSize *bytes_read,
+				GnomeVFSCancellation *cancellation)
 {
-	gint read_val;
+	gint     read_val;
+	fd_set   read_fds;
+	int max_fd, cancel_fd;
+
+	cancel_fd = -1;
+	
+read_loop:
+	read_val = read (connection->sock, buffer, bytes);
+
+	if (read_val == -1 && errno == EAGAIN) {
+
+		FD_ZERO (&read_fds);
+		FD_SET (connection->sock, &read_fds);
+		max_fd = connection->sock;
+	
+		if (cancellation != NULL) {
+			cancel_fd = gnome_vfs_cancellation_get_fd (cancellation);
+			FD_SET (cancel_fd, &read_fds);
+			max_fd = MAX (max_fd, cancel_fd);
+		}
+		
+		read_val = select (max_fd + 1, &read_fds, NULL, NULL, NULL);
 
-	do {
-		read_val = read (connection->sock, buffer, bytes);
-	} while (read_val == -1 && errno == EINTR);
+		if (read_val != -1) { 	
 
+			if (cancel_fd != -1 && FD_ISSET (cancel_fd, &read_fds)) {
+				return GNOME_VFS_ERROR_CANCELLED;
+			}
+			
+			if (FD_ISSET (connection->sock, &read_fds)) {
+				goto read_loop;
+			}
+
+		}
+	} 
+	
 	if (read_val == -1) {
 		*bytes_read = 0;
-		return gnome_vfs_result_from_errno ();
+
+		if (gnome_vfs_cancellation_check (cancellation)) {
+			return GNOME_VFS_ERROR_CANCELLED;
+		} 
+		
+		if (errno == EINTR) {
+			goto read_loop;
+		} else {
+			return gnome_vfs_result_from_errno ();
+		}
+
 	} else {
 		*bytes_read = read_val;
 	}
 
-	return bytes_read == 0 ? GNOME_VFS_ERROR_EOF : GNOME_VFS_OK;
+	return *bytes_read == 0 ? GNOME_VFS_ERROR_EOF : GNOME_VFS_OK;
 }
 
 /**
@@ -286,17 +333,59 @@ static GnomeVFSResult 
 gnome_vfs_inet_connection_write (GnomeVFSInetConnection *connection,
 			         gconstpointer buffer,
 			         GnomeVFSFileSize bytes,
-			         GnomeVFSFileSize *bytes_written)
+			         GnomeVFSFileSize *bytes_written,
+				 GnomeVFSCancellation *cancellation)
 {
-	gint write_val;
+	gint    write_val;
+	fd_set  write_fds;
+	int max_fd, cancel_fd;
+
+
+	cancel_fd = -1;
+	
+write_loop:	
+	write_val = write (connection->sock, buffer, bytes);
+		
+	if (write_val == -1 && errno == EAGAIN) {
+			
+         	FD_ZERO (&write_fds);
+		FD_SET (connection->sock, &write_fds);
+		max_fd = connection->sock;
+
+		if (cancellation != NULL) {
+			cancel_fd = gnome_vfs_cancellation_get_fd (cancellation);
+			FD_SET (cancel_fd, &write_fds);
+			max_fd = MAX (max_fd, cancel_fd);
+		}
+		
+		write_val = select (max_fd + 1, NULL, &write_fds, NULL, NULL);
+				
+		if (write_val != -1) { 	
 
-	do {
-		write_val = write (connection->sock, buffer, bytes);
-	} while (write_val == -1 && errno == EINTR);
+			if (cancel_fd != -1 && FD_ISSET (cancel_fd, &write_fds)) {
+				return GNOME_VFS_ERROR_CANCELLED;
+			}
+			
+			if (FD_ISSET (connection->sock, &write_fds)) {
+				goto write_loop;
+			}
+
+		}
+	}
 
 	if (write_val == -1) {
 		*bytes_written = 0;
-		return gnome_vfs_result_from_errno ();
+
+	        if (gnome_vfs_cancellation_check (cancellation)) {
+			return GNOME_VFS_ERROR_CANCELLED;
+		}
+
+		if (errno == EINTR) {
+			goto write_loop;
+		} else {
+			return gnome_vfs_result_from_errno ();
+		}
+
 	} else {
 		*bytes_written = write_val;
 		return GNOME_VFS_OK;
Index: libgnomevfs/gnome-vfs-socket-buffer.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-socket-buffer.c,v
retrieving revision 1.8
diff -u -p -r1.8 gnome-vfs-socket-buffer.c
--- libgnomevfs/gnome-vfs-socket-buffer.c	15 Jan 2004 09:55:51 -0000	1.8
+++ libgnomevfs/gnome-vfs-socket-buffer.c	1 Apr 2004 13:23:55 -0000
@@ -98,12 +98,13 @@ gnome_vfs_socket_buffer_new (GnomeVFSSoc
  **/
 GnomeVFSResult   
 gnome_vfs_socket_buffer_destroy  (GnomeVFSSocketBuffer *socket_buffer, 
-				  gboolean close_socket)
+				  gboolean close_socket,
+				  GnomeVFSCancellation *cancellation)
 {
-	gnome_vfs_socket_buffer_flush (socket_buffer);
+	gnome_vfs_socket_buffer_flush (socket_buffer, cancellation);
 
         if (close_socket) {
-		gnome_vfs_socket_close (socket_buffer->socket);
+		gnome_vfs_socket_close (socket_buffer->socket, cancellation);
 	}
 	g_free (socket_buffer);
 	return GNOME_VFS_OK;
@@ -113,7 +114,8 @@ gnome_vfs_socket_buffer_destroy  (GnomeV
 
 
 static gboolean
-refill_input_buffer (GnomeVFSSocketBuffer *socket_buffer)
+refill_input_buffer (GnomeVFSSocketBuffer *socket_buffer,
+		     GnomeVFSCancellation *cancellation)
 {
 	Buffer *input_buffer;
 	GnomeVFSResult result;
@@ -131,11 +133,15 @@ refill_input_buffer (GnomeVFSSocketBuffe
 	result = gnome_vfs_socket_read (socket_buffer->socket,
 					&input_buffer->data, 
 					BUFFER_SIZE,
-					&bytes_read);
+					&bytes_read,
+					cancellation);
 	
 	if (bytes_read == 0) {
 		input_buffer->last_error = GNOME_VFS_ERROR_EOF;
 		return FALSE;
+	} else if (result != GNOME_VFS_OK) {
+		input_buffer->last_error = result;
+		return FALSE;
 	}
 
 	input_buffer->byte_count = bytes_read;
@@ -159,7 +165,8 @@ GnomeVFSResult   
 gnome_vfs_socket_buffer_read (GnomeVFSSocketBuffer *socket_buffer,
 			      gpointer buffer,
 			      GnomeVFSFileSize bytes,
-			      GnomeVFSFileSize *bytes_read)
+			      GnomeVFSFileSize *bytes_read,
+			      GnomeVFSCancellation *cancellation)
 {
 	Buffer *input_buffer;
 	GnomeVFSResult result;
@@ -181,7 +188,7 @@ gnome_vfs_socket_buffer_read (GnomeVFSSo
 	result = GNOME_VFS_OK;
 
 	if (input_buffer->byte_count == 0) {
-		if (! refill_input_buffer (socket_buffer)) {
+		if (! refill_input_buffer (socket_buffer, cancellation)) {
 			/* The buffer is empty but we had an error last time we
 			   filled it, so we report the error.  */
 			result = input_buffer->last_error;
@@ -220,7 +227,8 @@ gnome_vfs_socket_buffer_read (GnomeVFSSo
  **/
 GnomeVFSResult
 gnome_vfs_socket_buffer_peekc (GnomeVFSSocketBuffer *socket_buffer,
-			       gchar *character)
+			       gchar *character,
+			       GnomeVFSCancellation *cancellation)
 {
 	GnomeVFSResult result;
 	Buffer *input_buffer;
@@ -232,7 +240,7 @@ gnome_vfs_socket_buffer_peekc (GnomeVFSS
 	result = GNOME_VFS_OK;
 
 	if (input_buffer->byte_count == 0) {
-		if (!refill_input_buffer (socket_buffer)) {
+		if (!refill_input_buffer (socket_buffer, cancellation)) {
 			/* The buffer is empty but we had an error last time we
 			   filled it, so we report the error.  */
 			result = input_buffer->last_error;
@@ -250,7 +258,8 @@ gnome_vfs_socket_buffer_peekc (GnomeVFSS
 
 
 static GnomeVFSResult
-flush (GnomeVFSSocketBuffer *socket_buffer)
+flush (GnomeVFSSocketBuffer *socket_buffer,
+       GnomeVFSCancellation *cancellation)
 {
 	Buffer *output_buffer;
 	GnomeVFSResult result;
@@ -262,8 +271,14 @@ flush (GnomeVFSSocketBuffer *socket_buff
 		result = gnome_vfs_socket_write (socket_buffer->socket, 
 						 output_buffer->data,
 						 output_buffer->byte_count,
-						 &bytes_written);
+						 &bytes_written,
+						 cancellation);
 		output_buffer->last_error = result;
+
+		if (result != GNOME_VFS_OK) {
+			return result;
+		}
+		
 		output_buffer->byte_count -= bytes_written;
 	}
 
@@ -286,7 +301,8 @@ GnomeVFSResult   
 gnome_vfs_socket_buffer_write (GnomeVFSSocketBuffer *socket_buffer, 
 			       gconstpointer buffer,
 			       GnomeVFSFileSize bytes,
-			       GnomeVFSFileSize *bytes_written)
+			       GnomeVFSFileSize *bytes_written,
+			       GnomeVFSCancellation *cancellation)
 {
 	Buffer *output_buffer;
 	GnomeVFSFileSize write_count;
@@ -315,7 +331,7 @@ gnome_vfs_socket_buffer_write (GnomeVFSS
 			write_count += n;
 			output_buffer->byte_count += n;
 		} else {
-			result = flush (socket_buffer);
+			result = flush (socket_buffer, cancellation);
 			if (result != GNOME_VFS_OK) {
 				break;
 			}
@@ -338,11 +354,12 @@ gnome_vfs_socket_buffer_write (GnomeVFSS
  * Return value: GnomeVFSResult indicating the success of the operation
  **/
 GnomeVFSResult   
-gnome_vfs_socket_buffer_flush (GnomeVFSSocketBuffer *socket_buffer)
+gnome_vfs_socket_buffer_flush (GnomeVFSSocketBuffer *socket_buffer,
+			       GnomeVFSCancellation *cancellation)
 {
 	g_return_val_if_fail (socket_buffer != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
 
-	return flush (socket_buffer);
+	return flush (socket_buffer, cancellation);
 }
 
 
Index: libgnomevfs/gnome-vfs-socket-buffer.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-socket-buffer.h,v
retrieving revision 1.5
diff -u -p -r1.5 gnome-vfs-socket-buffer.h
--- libgnomevfs/gnome-vfs-socket-buffer.h	16 Jun 2002 23:43:34 -0000	1.5
+++ libgnomevfs/gnome-vfs-socket-buffer.h	1 Apr 2004 13:23:55 -0000
@@ -38,18 +38,23 @@ typedef struct GnomeVFSSocketBuffer Gnom
 
 GnomeVFSSocketBuffer* gnome_vfs_socket_buffer_new      (GnomeVFSSocket       *socket);
 GnomeVFSResult        gnome_vfs_socket_buffer_destroy  (GnomeVFSSocketBuffer *socket_buffer,
-							gboolean              close_socket);
+							gboolean              close_socket,
+							GnomeVFSCancellation *cancellation);
 GnomeVFSResult        gnome_vfs_socket_buffer_read     (GnomeVFSSocketBuffer *socket_buffer, 
 							gpointer              buffer,
 							GnomeVFSFileSize      bytes, 
-							GnomeVFSFileSize     *bytes_read);
+							GnomeVFSFileSize     *bytes_read,
+							GnomeVFSCancellation *cancellation);
 GnomeVFSResult        gnome_vfs_socket_buffer_peekc    (GnomeVFSSocketBuffer *socket_buffer, 
-							char                 *character);
+							char                 *character,
+							GnomeVFSCancellation *cancellation);
 GnomeVFSResult        gnome_vfs_socket_buffer_write    (GnomeVFSSocketBuffer *socket_buffer,
 							gconstpointer         buffer,
 							GnomeVFSFileSize      bytes,
-							GnomeVFSFileSize     *bytes_written);
-GnomeVFSResult        gnome_vfs_socket_buffer_flush    (GnomeVFSSocketBuffer *socket_buffer);
+							GnomeVFSFileSize     *bytes_written,
+							GnomeVFSCancellation *cancellation);
+GnomeVFSResult        gnome_vfs_socket_buffer_flush    (GnomeVFSSocketBuffer *socket_buffer,
+							GnomeVFSCancellation *cancellation);
 
 G_END_DECLS
 
Index: libgnomevfs/gnome-vfs-socket.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-socket.c,v
retrieving revision 1.8
diff -u -p -r1.8 gnome-vfs-socket.c
--- libgnomevfs/gnome-vfs-socket.c	5 Feb 2004 13:34:23 -0000	1.8
+++ libgnomevfs/gnome-vfs-socket.c	1 Apr 2004 13:23:55 -0000
@@ -68,6 +68,7 @@ GnomeVFSSocket* gnome_vfs_socket_new (Gn
  * @bytes: number of bytes from @buffer to write to @socket
  * @bytes_written: pointer to a GnomeVFSFileSize, will contain
  * the number of bytes actually written to the socket on return.
+ * @cancellation: optional cancellation object
  *
  * Write @bytes bytes of data from @buffer to @socket.
  *
@@ -77,24 +78,28 @@ GnomeVFSResult  
 gnome_vfs_socket_write (GnomeVFSSocket *socket, 
 			gconstpointer buffer,
 			int bytes, 
-			GnomeVFSFileSize *bytes_written)
+			GnomeVFSFileSize *bytes_written,
+			GnomeVFSCancellation *cancellation)
 {
 	return socket->impl->write (socket->connection,
-				    buffer, bytes, bytes_written);
+				    buffer, bytes, bytes_written,
+				    cancellation);
 }
 
 /**
  * gnome_vfs_socket_close:
  * @socket: the socket to be closed
+ * @cancellation: optional cancellation object
  *
  * Close @socket, freeing any resources it may be using.
  *
  * Return value: GnomeVFSResult indicating the success of the operation
  **/
 GnomeVFSResult  
-gnome_vfs_socket_close (GnomeVFSSocket *socket)
+gnome_vfs_socket_close (GnomeVFSSocket *socket,
+			GnomeVFSCancellation *cancellation)
 {
-	socket->impl->close (socket->connection);
+	socket->impl->close (socket->connection, cancellation);
 	g_free (socket);
 	return GNOME_VFS_OK;
 }
@@ -106,6 +111,7 @@ gnome_vfs_socket_close (GnomeVFSSocket *
  * @bytes: number of bytes to read from @socket into @buffer
  * @bytes_read: pointer to a GnomeVFSFileSize, will contain
  * the number of bytes actually read from the socket on return.
+ * @cancellation: optional cancellation object
  *
  * Read @bytes bytes of data from the @socket into @buffer.
  *
@@ -115,8 +121,10 @@ GnomeVFSResult  
 gnome_vfs_socket_read  (GnomeVFSSocket *socket, 
 			gpointer buffer, 
 			GnomeVFSFileSize bytes,
-			GnomeVFSFileSize *bytes_read)
+			GnomeVFSFileSize *bytes_read,
+			GnomeVFSCancellation *cancellation)
 {
 	return socket->impl->read (socket->connection,
-				   buffer, bytes, bytes_read);
+				   buffer, bytes, bytes_read,
+				   cancellation);
 }
Index: libgnomevfs/gnome-vfs-socket.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-socket.h,v
retrieving revision 1.7
diff -u -p -r1.7 gnome-vfs-socket.h
--- libgnomevfs/gnome-vfs-socket.h	3 Aug 2001 00:39:58 -0000	1.7
+++ libgnomevfs/gnome-vfs-socket.h	1 Apr 2004 13:23:55 -0000
@@ -30,6 +30,7 @@
 #define GNOME_VFS_SOCKET_H
 
 #include <glib/gtypes.h>
+#include <libgnomevfs/gnome-vfs-cancellation.h>
 #include <libgnomevfs/gnome-vfs-file-size.h>
 #include <libgnomevfs/gnome-vfs-result.h>
 
@@ -37,17 +38,19 @@ G_BEGIN_DECLS
 
 typedef struct GnomeVFSSocket GnomeVFSSocket;
 
-
 typedef GnomeVFSResult (*GnomeVFSSocketReadFunc)  (gpointer connection,
 						   gpointer buffer, 
 						   GnomeVFSFileSize bytes, 
-						   GnomeVFSFileSize *bytes_read);
+						   GnomeVFSFileSize *bytes_read,
+						   GnomeVFSCancellation *cancellation);
 typedef GnomeVFSResult (*GnomeVFSSocketWriteFunc) (gpointer connection, 
 						   gconstpointer buffer,
 						   GnomeVFSFileSize bytes,
-						   GnomeVFSFileSize *bytes_written);
+						   GnomeVFSFileSize *bytes_written,
+						   GnomeVFSCancellation *cancellation);
 
-typedef void           (*GnomeVFSSocketCloseFunc) (gpointer connection);
+typedef void           (*GnomeVFSSocketCloseFunc) (gpointer connection,
+						   GnomeVFSCancellation *cancellation);
 
 typedef struct {
   GnomeVFSSocketReadFunc read;
@@ -61,12 +64,15 @@ GnomeVFSSocket* gnome_vfs_socket_new    
 GnomeVFSResult  gnome_vfs_socket_write   (GnomeVFSSocket     *socket, 
 					  gconstpointer       buffer,
 					  int                 bytes, 
-					  GnomeVFSFileSize   *bytes_written);
-GnomeVFSResult  gnome_vfs_socket_close   (GnomeVFSSocket     *socket);
+					  GnomeVFSFileSize   *bytes_written,
+					  GnomeVFSCancellation *cancellation);
+GnomeVFSResult  gnome_vfs_socket_close   (GnomeVFSSocket     *socket,
+					  GnomeVFSCancellation *cancellation);
 GnomeVFSResult  gnome_vfs_socket_read    (GnomeVFSSocket     *socket, 
 					  gpointer            buffer, 
 					  GnomeVFSFileSize    bytes, 
-					  GnomeVFSFileSize   *bytes_read);
+					  GnomeVFSFileSize   *bytes_read,
+					  GnomeVFSCancellation *cancellation);
 
 G_END_DECLS
 
Index: libgnomevfs/gnome-vfs-ssl.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-ssl.c,v
retrieving revision 1.15
diff -u -p -r1.15 gnome-vfs-ssl.c
--- libgnomevfs/gnome-vfs-ssl.c	9 Mar 2004 20:37:33 -0000	1.15
+++ libgnomevfs/gnome-vfs-ssl.c	1 Apr 2004 13:23:55 -0000
@@ -80,6 +80,7 @@ _gnome_vfs_ssl_init () {
 #ifdef HAVE_OPENSSL
 	SSL_library_init ();
 #elif defined HAVE_GNUTLS
+#error "Need to update the GNUTLS code to support non-blocking fds and cancellation"
 	gnutls_global_init();
 #endif
 }
@@ -102,6 +103,53 @@ gnome_vfs_ssl_enabled ()
 #endif
 }
 
+#ifdef HAVE_OPENSSL
+static GnomeVFSResult
+handle_ssl_read_write (int fd, int error,
+		       GnomeVFSCancellation *cancellation)
+{
+	fd_set   read_fds;
+	fd_set   write_fds;
+	int res;
+	int max_fd;
+	int cancel_fd;
+
+	cancel_fd = -1;
+	
+ retry:
+	FD_ZERO (&read_fds);
+	FD_ZERO (&write_fds);
+	max_fd = fd;
+	
+	if (cancellation != NULL) {
+		cancel_fd = gnome_vfs_cancellation_get_fd (cancellation);
+		FD_SET (cancel_fd, &read_fds);
+		max_fd = MAX (max_fd, cancel_fd);
+	}
+	
+	if (error == SSL_ERROR_WANT_READ) {
+		FD_SET (fd, &read_fds);
+	}
+	if (error == SSL_ERROR_WANT_WRITE) {
+		FD_SET (fd, &write_fds);
+	}
+
+	res = select (max_fd + 1, &read_fds, &write_fds, NULL, NULL);
+	if (res == -1 && errno == EINTR) {
+		goto retry;
+	}
+	
+	if (res > 0) {
+		if (cancel_fd != -1 && FD_ISSET (cancel_fd, &read_fds)) {
+			return GNOME_VFS_ERROR_CANCELLED;
+		}
+
+		return GNOME_VFS_OK;
+	}
+	return GNOME_VFS_ERROR_INTERNAL;
+}
+#endif
+
 /**
  * gnome_vfs_ssl_create:
  * @handle_return: pointer to a GnmoeVFSSSL struct, which will
@@ -117,7 +165,8 @@ gnome_vfs_ssl_enabled ()
 GnomeVFSResult
 gnome_vfs_ssl_create (GnomeVFSSSL **handle_return, 
 		      const char *host, 
-		      unsigned int port)
+		      unsigned int port,
+		      GnomeVFSCancellation *cancellation)
 {
 /* FIXME: add *some* kind of cert verification! */
 #if defined(HAVE_OPENSSL) || defined(HAVE_GNUTLS)
@@ -208,7 +257,9 @@ gnome_vfs_ssl_create (GnomeVFSSSL **hand
 		return gnome_vfs_result_from_errno ();
 	}
 
-	return gnome_vfs_ssl_create_from_fd (handle_return, fd);
+	_gnome_vfs_set_fd_flags (fd, O_NONBLOCK);
+	
+	return gnome_vfs_ssl_create_from_fd (handle_return, fd, cancellation);
 #else
 	return GNOME_VFS_ERROR_NOT_SUPPORTED;
 #endif
@@ -228,6 +279,7 @@ static const int mac_priority[] =
 	{GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0};
 #endif
 
+
 /**
  * gnome_vfs_ssl_create_from_fd:
  * @handle_return: pointer to a GnmoeVFSSSL struct, which will
@@ -240,12 +292,15 @@ static const int mac_priority[] =
  **/
 GnomeVFSResult
 gnome_vfs_ssl_create_from_fd (GnomeVFSSSL **handle_return, 
-		              gint fd)
+		              gint fd,
+			      GnomeVFSCancellation *cancellation)
 {
 #ifdef HAVE_OPENSSL
 	GnomeVFSSSL *ssl;
 	SSL_CTX *ssl_ctx = NULL;
 	int ret;
+	int error;
+	GnomeVFSResult res;
 
 	ssl = g_new0 (GnomeVFSSSL, 1);
 	ssl->private = g_new0 (GnomeVFSSSLPrivate, 1);
@@ -267,9 +322,31 @@ gnome_vfs_ssl_create_from_fd (GnomeVFSSS
 
         SSL_set_fd (ssl->private->ssl, fd);
 
+ retry:
 	ret = SSL_connect (ssl->private->ssl);
 	if (ret != 1) {
-                SSL_shutdown (ssl->private->ssl);
+		error = SSL_get_error (ssl->private->ssl, ret);
+		res = GNOME_VFS_ERROR_IO;
+		if (error == SSL_ERROR_WANT_READ ||
+		    error == SSL_ERROR_WANT_WRITE) {
+			res = handle_ssl_read_write (fd, error, cancellation);
+			if (res == GNOME_VFS_OK) {
+				goto retry;
+			} 
+		} else if (error == SSL_ERROR_SYSCALL && ret != 0) {
+			res = gnome_vfs_result_from_errno ();
+		}
+
+	retry_shutdown:
+                ret = SSL_shutdown (ssl->private->ssl);
+		if (ret != 1) {
+			error = SSL_get_error (ssl->private->ssl, ret);
+			if (error == SSL_ERROR_WANT_READ ||
+			    error == SSL_ERROR_WANT_WRITE) {
+				/* No fancy select stuff here, just busy loop */
+				goto retry_shutdown;
+			}
+		}
 
                 if (ssl->private->ssl->ctx)
                         SSL_CTX_free (ssl->private->ssl->ctx);
@@ -277,7 +354,7 @@ gnome_vfs_ssl_create_from_fd (GnomeVFSSS
                 SSL_free (ssl->private->ssl);
 		g_free (ssl->private);
 		g_free (ssl);
-		return GNOME_VFS_ERROR_IO;
+		return res;
 	}
 
 	*handle_return = ssl;
@@ -352,20 +429,45 @@ GnomeVFSResult 
 gnome_vfs_ssl_read (GnomeVFSSSL *ssl,
 		    gpointer buffer,
 		    GnomeVFSFileSize bytes,
-		    GnomeVFSFileSize *bytes_read)
+		    GnomeVFSFileSize *bytes_read,
+		    GnomeVFSCancellation *cancellation)
 {
 #if HAVE_OPENSSL
+	int ret, error;
+	GnomeVFSResult res;
+	
 	if (bytes == 0) {
 		*bytes_read = 0;
 		return GNOME_VFS_OK;
 	}
 
-	*bytes_read = SSL_read (ssl->private->ssl, buffer, bytes);
-
-	if (*bytes_read <= 0) {
+ retry:
+	ret = SSL_read (ssl->private->ssl, buffer, bytes);
+	if (ret <= 0) {
+		res = GNOME_VFS_ERROR_IO;
+		error = SSL_get_error (ssl->private->ssl, ret);
+		if (error == SSL_ERROR_WANT_READ ||
+		    error == SSL_ERROR_WANT_WRITE) {
+			res = handle_ssl_read_write (SSL_get_fd (ssl->private->ssl),
+						     error, cancellation);
+			if (res == GNOME_VFS_OK) {
+				goto retry;
+			}
+		} else if (error == SSL_ERROR_SYSCALL) {
+			if (ret == 0) {
+				res = GNOME_VFS_ERROR_EOF;
+			} else {
+				res = gnome_vfs_result_from_errno ();
+			}
+		} else if (error == SSL_ERROR_ZERO_RETURN) {
+			res = GNOME_VFS_ERROR_EOF;
+		}
+		
 		*bytes_read = 0;
-		return GNOME_VFS_ERROR_GENERIC;
+		return res;
 	}
+	*bytes_read = ret;
+	
 	return GNOME_VFS_OK;
 #elif defined HAVE_GNUTLS
 	if (bytes == 0) {
@@ -401,20 +503,40 @@ GnomeVFSResult 
 gnome_vfs_ssl_write (GnomeVFSSSL *ssl,
 		     gconstpointer buffer,
 		     GnomeVFSFileSize bytes,
-		     GnomeVFSFileSize *bytes_written)
+		     GnomeVFSFileSize *bytes_written,
+		     GnomeVFSCancellation *cancellation)
 {
 #if HAVE_OPENSSL
+	int ret, error;
+	GnomeVFSResult res;
+	
 	if (bytes == 0) {
 		*bytes_written = 0;
 		return GNOME_VFS_OK;
 	}
 
-	*bytes_written = SSL_write (ssl->private->ssl, buffer, bytes);
+ retry:
+	ret = SSL_write (ssl->private->ssl, buffer, bytes);
 
-	if (*bytes_written <= 0) {
+	if (ret <= 0) {
+		res = GNOME_VFS_ERROR_IO;
+		
+		error = SSL_get_error (ssl->private->ssl, ret);
+		if (error == SSL_ERROR_WANT_READ ||
+		    error == SSL_ERROR_WANT_WRITE) {
+			res = handle_ssl_read_write (SSL_get_fd (ssl->private->ssl),
+						     error, cancellation);
+			if (res == GNOME_VFS_OK) {
+				goto retry;
+			}
+		} else if (error == SSL_ERROR_SYSCALL) {
+			res = gnome_vfs_result_from_errno ();
+		}
+	
 		*bytes_written = 0;
-		return GNOME_VFS_ERROR_GENERIC;
+		return res;
 	}
+	*bytes_written = ret;
 	return GNOME_VFS_OK;
 #elif defined HAVE_GNUTLS
 	if (bytes == 0) {
@@ -441,10 +563,27 @@ gnome_vfs_ssl_write (GnomeVFSSSL *ssl,
  * Free resources used by @ssl and close the connection.
  */
 void
-gnome_vfs_ssl_destroy (GnomeVFSSSL *ssl) 
+gnome_vfs_ssl_destroy (GnomeVFSSSL *ssl,
+		       GnomeVFSCancellation *cancellation) 
 {
 #if HAVE_OPENSSL
-	SSL_shutdown (ssl->private->ssl);
+	int ret, error;
+	GnomeVFSResult res;
+
+ retry:
+	ret = SSL_shutdown (ssl->private->ssl);
+	if (ret != 1) {
+		error = SSL_get_error (ssl->private->ssl, ret);
+		if (error == SSL_ERROR_WANT_READ ||
+		    error == SSL_ERROR_WANT_WRITE) {
+			res = handle_ssl_read_write (SSL_get_fd (ssl->private->ssl),
+						     error, cancellation);
+			if (res == GNOME_VFS_OK) {
+				goto retry;
+			}
+		}
+	}
+	
 	SSL_CTX_free (ssl->private->ssl->ctx);
 	SSL_free (ssl->private->ssl);
 	close (ssl->private->sockfd);
Index: libgnomevfs/gnome-vfs-ssl.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-ssl.h,v
retrieving revision 1.4
diff -u -p -r1.4 gnome-vfs-ssl.h
--- libgnomevfs/gnome-vfs-ssl.h	3 Aug 2001 00:39:58 -0000	1.4
+++ libgnomevfs/gnome-vfs-ssl.h	1 Apr 2004 13:23:55 -0000
@@ -36,18 +36,23 @@ gboolean        gnome_vfs_ssl_enabled   
 /* FIXME: add *some* kind of cert verification! */
 GnomeVFSResult  gnome_vfs_ssl_create         (GnomeVFSSSL **handle_return,
 		                              const char *host, 
-		                              unsigned int port);
+		                              unsigned int port,
+					      GnomeVFSCancellation *cancellation);
 GnomeVFSResult  gnome_vfs_ssl_create_from_fd (GnomeVFSSSL **handle_return,
-					      gint fd);
+					      gint fd,
+					      GnomeVFSCancellation *cancellation);
 GnomeVFSResult  gnome_vfs_ssl_read           (GnomeVFSSSL *ssl,
 					      gpointer buffer,
 					      GnomeVFSFileSize bytes,
-				      	      GnomeVFSFileSize *bytes_read);
+				      	      GnomeVFSFileSize *bytes_read,
+					      GnomeVFSCancellation *cancellation);
 GnomeVFSResult  gnome_vfs_ssl_write          (GnomeVFSSSL *ssl,
 					      gconstpointer buffer,
 					      GnomeVFSFileSize bytes,
-					      GnomeVFSFileSize *bytes_written);
-void            gnome_vfs_ssl_destroy        (GnomeVFSSSL *ssl);
+					      GnomeVFSFileSize *bytes_written,
+					      GnomeVFSCancellation *cancellation);
+void            gnome_vfs_ssl_destroy        (GnomeVFSSSL *ssl,
+					      GnomeVFSCancellation *cancellation);
 GnomeVFSSocket *gnome_vfs_ssl_to_socket      (GnomeVFSSSL *ssl);
 
 G_END_DECLS
Index: modules/ftp-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/ftp-method.c,v
retrieving revision 1.98
diff -u -p -r1.98 ftp-method.c
--- modules/ftp-method.c	19 Mar 2004 10:54:47 -0000	1.98
+++ modules/ftp-method.c	1 Apr 2004 13:23:55 -0000
@@ -152,6 +152,15 @@ FTP_DEBUG (FtpConnection *conn, 
 
 #endif
 
+static GnomeVFSCancellation *
+get_cancellation (GnomeVFSContext *context)
+{
+	if (context) {
+		return gnome_vfs_context_get_cancellation (context);
+	}
+	return NULL;
+}
+
 static GnomeVFSResult 
 ftp_response_to_vfs_result (FtpConnection *conn) 
 {
@@ -197,7 +206,8 @@ ftp_response_to_vfs_result (FtpConnectio
 
 }
 
-static GnomeVFSResult read_response_line(FtpConnection *conn, gchar **line) {
+static GnomeVFSResult read_response_line(FtpConnection *conn, gchar **line,
+					 GnomeVFSCancellation *cancellation) {
 	GnomeVFSFileSize bytes = MAX_RESPONSE_SIZE, bytes_read;
 	gchar *ptr, *buf = g_malloc (MAX_RESPONSE_SIZE+1);
 	gint line_length;
@@ -208,7 +218,7 @@ static GnomeVFSResult read_response_line
 		/*ftp_debug (conn,g_strdup_printf ("response `%s' is incomplete", conn->response_buffer->str));*/
 		bytes_read = 0;
 		result = gnome_vfs_socket_buffer_read (conn->socket_buf, buf,
-						       bytes, &bytes_read);
+						       bytes, &bytes_read, cancellation);
 		buf[bytes_read] = '\0';
 		/*ftp_debug (conn,g_strdup_printf ("read `%s'", buf));*/
 		conn->response_buffer = g_string_append (conn->response_buffer,
@@ -234,7 +244,7 @@ static GnomeVFSResult read_response_line
 }
 
 static GnomeVFSResult
-get_response (FtpConnection *conn)
+get_response (FtpConnection *conn, GnomeVFSCancellation *cancellation)
 {
 	/* all that should be pending is a response to the last command */
 	GnomeVFSResult result;
@@ -243,7 +253,7 @@ get_response (FtpConnection *conn)
 
 	while (TRUE) {
 		gchar *line = NULL;
-		result = read_response_line (conn, &line);
+		result = read_response_line (conn, &line, cancellation);
 
 		if (result != GNOME_VFS_OK) {
 			g_free (line);
@@ -287,16 +297,17 @@ get_response (FtpConnection *conn)
 }
 
 static GnomeVFSResult do_control_write (FtpConnection *conn, 
-					gchar *command) 
+					gchar *command,
+					GnomeVFSCancellation *cancellation) 
 {
         gchar *actual_command = g_strdup_printf ("%s\r\n", command);
 	GnomeVFSFileSize bytes = strlen (actual_command), bytes_written;
 	GnomeVFSResult result = gnome_vfs_socket_buffer_write (conn->socket_buf,
-							       actual_command, bytes, &bytes_written);
+							       actual_command, bytes, &bytes_written, cancellation);
 #if 0
 	ftp_debug (conn, g_strdup_printf ("sent \"%s\\r\\n\"", command));
 #endif
-	gnome_vfs_socket_buffer_flush (conn->socket_buf);
+	gnome_vfs_socket_buffer_flush (conn->socket_buf, cancellation);
 
 	if(result != GNOME_VFS_OK) {
 		g_free (actual_command);
@@ -315,15 +326,16 @@ static GnomeVFSResult do_control_write (
 
 static GnomeVFSResult 
 do_basic_command (FtpConnection *conn, 
-		  gchar *command) 
+		  gchar *command,
+		  GnomeVFSCancellation *cancellation) 
 {
-	GnomeVFSResult result = do_control_write(conn, command);
+	GnomeVFSResult result = do_control_write (conn, command, cancellation);
 
 	if (result != GNOME_VFS_OK) {
 		return result;
 	}
 
-	result = get_response (conn);
+	result = get_response (conn, cancellation);
 
 	return result;
 }
@@ -331,7 +343,8 @@ do_basic_command (FtpConnection *conn, 
 static GnomeVFSResult 
 do_path_command (FtpConnection *conn, 
 		 gchar *command,
-		 GnomeVFSURI *uri) 
+		 GnomeVFSURI *uri,
+		 GnomeVFSCancellation *cancellation) 
 {
 	char *path;
 	char *actual_command;
@@ -350,7 +363,7 @@ do_path_command (FtpConnection *conn, 
 	}
 	g_free (path);
 
-	result = do_basic_command (conn, actual_command);
+	result = do_basic_command (conn, actual_command, cancellation);
 	g_free (actual_command);
 	return result;
 }
@@ -363,14 +376,16 @@ do_path_command_completely (gchar *comma
 {
 	FtpConnection *conn;
 	GnomeVFSResult result;
-
+	GnomeVFSCancellation *cancellation;
+	
+	cancellation = get_cancellation (context);
 	result = ftp_connection_acquire (uri, &conn, context);
 	if (result != GNOME_VFS_OK) {
 		return result;
 	}
 
 	conn->fivefifty = fivefifty;
-	result = do_path_command (conn, command, uri);
+	result = do_path_command (conn, command, uri, cancellation);
 	ftp_connection_release (conn);
 
 	return result;
@@ -384,14 +399,16 @@ do_transfer_command (FtpConnection *conn
 	GnomeVFSResult result;
 	GnomeVFSInetConnection *data_connection;
 	GnomeVFSSocket *socket;
-
+	GnomeVFSCancellation *cancellation;
+	
+	cancellation = get_cancellation (context);
 	/* Image mode (binary to the uninitiated) */
-	do_basic_command (conn, "TYPE I");
+	do_basic_command (conn, "TYPE I", cancellation);
 
 	/* FIXME bugzilla.eazel.com 1464: implement non-PASV mode */
 
 	/* send PASV */
-	do_basic_command (conn, "PASV");
+	do_basic_command (conn, "PASV", cancellation);
 
 	/* parse response */
 	{
@@ -416,7 +433,7 @@ do_transfer_command (FtpConnection *conn
 	result = gnome_vfs_inet_connection_create (&data_connection,
 						   host, 
 						   port,
-						   context ? gnome_vfs_context_get_cancellation(context) : NULL);
+						   cancellation);
 
 	g_free (host);
 	if (result != GNOME_VFS_OK) {
@@ -430,26 +447,26 @@ do_transfer_command (FtpConnection *conn
 		gchar *tmpstring;
 
 		tmpstring = g_strdup_printf ("REST %Lu", conn->offset);
-		result = do_basic_command (conn, tmpstring);
+		result = do_basic_command (conn, tmpstring, cancellation);
 		g_free (tmpstring);
 
 		if (result != GNOME_VFS_OK) {
-			gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
+			gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE, cancellation);
 			return result;
 		}
 	}
 
-	result = do_control_write (conn, command);
+	result = do_control_write (conn, command, cancellation);
 
 	if (result != GNOME_VFS_OK) {
-		gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
+		gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE, cancellation);
 		return result;
 	}
 
-	result = get_response (conn);
+	result = get_response (conn, cancellation);
 
 	if (result != GNOME_VFS_OK) {
-		gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
+		gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE, cancellation);
 		return result;
 	}
 
@@ -483,19 +500,20 @@ do_path_transfer_command (FtpConnection 
 
 
 static GnomeVFSResult 
-end_transfer (FtpConnection *conn) 
+end_transfer (FtpConnection *conn,
+	      GnomeVFSCancellation *cancellation) 
 {
 	GnomeVFSResult result;
 
 	/*ftp_debug (conn, g_strdup ("end_transfer()"));*/
 
 	if(conn->data_socketbuf) {
-		gnome_vfs_socket_buffer_flush (conn->data_socketbuf);
-		gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
+		gnome_vfs_socket_buffer_flush (conn->data_socketbuf, cancellation);
+		gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE, cancellation);
 		conn->data_socketbuf = NULL;
 	}
 
-	result = get_response (conn);
+	result = get_response (conn, cancellation);
 
 	return result;
 
@@ -503,18 +521,19 @@ end_transfer (FtpConnection *conn) 
 
 
 static GnomeVFSResult ftp_login (FtpConnection *conn, 
-                                 const char *user, const char *password)
+                                 const char *user, const char *password,
+				 GnomeVFSCancellation *cancellation)
 {
 	gchar *tmpstring;
 	GnomeVFSResult result;
 	
 	tmpstring = g_strdup_printf ("USER %s", user);
-	result = do_basic_command (conn, tmpstring);
+	result = do_basic_command (conn, tmpstring, cancellation);
 	g_free (tmpstring);
 
 	if (IS_300 (conn->response_code)) {
 		tmpstring = g_strdup_printf ("PASS %s", password);
-		result = do_basic_command (conn, tmpstring);
+		result = do_basic_command (conn, tmpstring, cancellation);
 		g_free (tmpstring);
 	}
 
@@ -531,7 +550,9 @@ ftp_connection_create (FtpConnection **c
 	const gchar *user = anon_user;
 	const gchar *pass = anon_pass;
 	GnomeVFSInetConnection* inet_connection;
+	GnomeVFSCancellation *cancellation;
 	
+	cancellation = get_cancellation (context);
 	conn->uri = gnome_vfs_uri_dup (uri);
 	conn->response_buffer = g_string_new ("");
 	conn->response_code = -1;
@@ -554,7 +575,7 @@ ftp_connection_create (FtpConnection **c
 	result = gnome_vfs_inet_connection_create (&inet_connection, 
 						   gnome_vfs_uri_get_host_name (uri), 
 						   port, 
-						   context ? gnome_vfs_context_get_cancellation(context) : NULL);
+						   cancellation);
 	
 	if (result != GNOME_VFS_OK) {
 	        g_warning ("gnome_vfs_inet_connection_create (\"%s\", %d) = \"%s\"",
@@ -579,7 +600,7 @@ ftp_connection_create (FtpConnection **c
 	}
 	conn->offset = 0;
 
-	result = get_response (conn);
+	result = get_response (conn, cancellation);
 
 	if (result != GNOME_VFS_OK) { 
 		g_warning ("ftp server (%s:%d) said `%d %s'", 
@@ -592,13 +613,13 @@ ftp_connection_create (FtpConnection **c
 		return result;
 	}
 
-	result = ftp_login(conn, user, pass);
+	result = ftp_login(conn, user, pass, cancellation);
 
 	if (result != GNOME_VFS_OK) {
 		/* login failed */
 		g_warning ("FTP server said: \"%d %s\"\n", conn->response_code,
 			   conn->response_message);
-		gnome_vfs_socket_buffer_destroy (conn->socket_buf, TRUE);
+		gnome_vfs_socket_buffer_destroy (conn->socket_buf, TRUE, cancellation);
 		gnome_vfs_uri_unref (conn->uri);
 		g_string_free (conn->response_buffer, TRUE);
 		g_free (conn);
@@ -610,11 +631,11 @@ ftp_connection_create (FtpConnection **c
 
 	/* Image mode (binary to the uninitiated) */
 
-	do_basic_command (conn, "TYPE I");
+	do_basic_command (conn, "TYPE I", cancellation);
 
 	/* Get the system type */
 
-	do_basic_command (conn, "SYST");
+	do_basic_command (conn, "SYST", cancellation);
 	conn->server_type=g_strdup(conn->response_message);
 
 	*connptr = conn;
@@ -627,11 +648,12 @@ ftp_connection_create (FtpConnection **c
 }
 
 static void
-ftp_connection_destroy (FtpConnection *conn) 
+ftp_connection_destroy (FtpConnection *conn,
+			GnomeVFSCancellation *cancellation) 
 {
 
 	if (conn->socket_buf) 
-	        gnome_vfs_socket_buffer_destroy (conn->socket_buf, TRUE);
+	        gnome_vfs_socket_buffer_destroy (conn->socket_buf, TRUE, cancellation);
 
 	gnome_vfs_uri_unref (conn->uri);
 	g_free (conn->cwd);
@@ -642,7 +664,7 @@ ftp_connection_destroy (FtpConnection *c
 	g_free (conn->server_type);
 
 	if (conn->data_socketbuf) 
-	        gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
+	        gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE, cancellation);
 
 	g_free (conn->dirlist);
 	g_free (conn->dirlistptr);
@@ -708,7 +730,9 @@ ftp_connection_acquire (GnomeVFSURI *uri
 	GList *possible_connections;
 	FtpConnection *conn = NULL;
 	GnomeVFSResult result = GNOME_VFS_OK;
-
+	GnomeVFSCancellation *cancellation;
+	
+	cancellation = get_cancellation (context);
 	G_LOCK (spare_connections);
 
 	if (spare_connections == NULL) {
@@ -734,9 +758,9 @@ ftp_connection_acquire (GnomeVFSURI *uri
 		g_hash_table_insert (spare_connections, uri, 
 				     possible_connections);
 		/* make sure connection hasn't timed out */
-		result = do_basic_command(conn, "PWD");
+		result = do_basic_command(conn, "PWD", cancellation);
 		if (result != GNOME_VFS_OK) {
-			ftp_connection_destroy (conn);
+			ftp_connection_destroy (conn, cancellation);
 			result = ftp_connection_create (&conn, uri, context);
 		}
 
@@ -858,9 +882,11 @@ do_close (GnomeVFSMethod *method,
 	  GnomeVFSContext *context) 
 {
 	FtpConnection *conn = (FtpConnection *) method_handle;
-
-	GnomeVFSResult result = end_transfer (conn);
-
+	GnomeVFSResult result;
+	GnomeVFSCancellation *cancellation;
+	
+	cancellation = get_cancellation (context);
+	result = end_transfer (conn, cancellation);
 	ftp_connection_release (conn);
 
 	return result;
@@ -876,6 +902,9 @@ do_read (GnomeVFSMethod *method, 
 {
 	FtpConnection *conn = (FtpConnection * )method_handle;
 	GnomeVFSResult result;
+	GnomeVFSCancellation *cancellation;
+	
+	cancellation = get_cancellation (context);
 #if 0
 	/*
 	if (conn->operation != FTP_READ) {
@@ -884,7 +913,7 @@ do_read (GnomeVFSMethod *method, 
 	}*/
 	g_print ("do_read (%p)\n", method_handle);
 #endif
-	result = gnome_vfs_socket_buffer_read (conn->data_socketbuf, buffer, num_bytes, bytes_read);
+	result = gnome_vfs_socket_buffer_read (conn->data_socketbuf, buffer, num_bytes, bytes_read, cancellation);
 
  	if (*bytes_read == 0) {
  		result = GNOME_VFS_ERROR_EOF;
@@ -907,6 +936,9 @@ do_write (GnomeVFSMethod *method, 
 {
 	FtpConnection *conn = (FtpConnection *) method_handle;
 	GnomeVFSResult result;
+	GnomeVFSCancellation *cancellation;
+	
+	cancellation = get_cancellation (context);
 
 #if 0
 	g_print ("do_write ()\n");
@@ -917,7 +949,7 @@ do_write (GnomeVFSMethod *method, 
 	
 	result = gnome_vfs_socket_buffer_write (conn->data_socketbuf, buffer, 
 						num_bytes, 
-						bytes_written);
+						bytes_written, cancellation);
 
 	if (result == GNOME_VFS_OK) {
 		conn->offset += *bytes_written;
@@ -937,7 +969,10 @@ do_seek (GnomeVFSMethod *method,
 	GnomeVFSResult result;
 	GnomeVFSFileOffset real_offset;
 	GnomeVFSFileOffset orig_offset;
-
+	GnomeVFSCancellation *cancellation;
+	
+	cancellation = get_cancellation (context);
+	
 	/* Calculate real offset */
 	switch (whence) {
 		case GNOME_VFS_SEEK_START:
@@ -953,7 +988,7 @@ do_seek (GnomeVFSMethod *method,
 	}
 
 	/* We need to stop the data transfer first */
-	result = end_transfer (conn);
+	result = end_transfer (conn, cancellation);
 
 	/* Do not check for result != GNOME_VFS_OK because we know the error:
 	 * 426 Failure writing network stream.
@@ -1445,7 +1480,10 @@ do_open_directory (GnomeVFSMethod *metho
 	GnomeVFSFileSize num_bytes = BUFFER_SIZE, bytes_read;
 	gchar buffer[BUFFER_SIZE+1];
 	GString *dirlist = g_string_new ("");
+	GnomeVFSCancellation *cancellation;
 
+	cancellation = get_cancellation (context);
+	
 	result = ftp_connection_acquire (uri, &conn, context);
 	if (result != GNOME_VFS_OK) {
 		g_string_free (dirlist, TRUE);
@@ -1460,7 +1498,7 @@ do_open_directory (GnomeVFSMethod *metho
 	 * connections stateless?
 	 */
 	conn->fivefifty = GNOME_VFS_ERROR_NOT_A_DIRECTORY;
-	result = do_path_command (conn, "CWD", uri);
+	result = do_path_command (conn, "CWD", uri, cancellation);
 	if (result != GNOME_VFS_OK) {
 		ftp_connection_release (conn);
 		return result;
@@ -1483,7 +1521,8 @@ do_open_directory (GnomeVFSMethod *metho
 
 	while (result == GNOME_VFS_OK) {
 		result = gnome_vfs_socket_buffer_read (conn->data_socketbuf, buffer, 
-					       num_bytes, &bytes_read);
+						       num_bytes, &bytes_read,
+						       cancellation);
 		if (result == GNOME_VFS_OK && bytes_read > 0) {
 			buffer[bytes_read] = '\0';
 			dirlist = g_string_append (dirlist, buffer);
@@ -1492,7 +1531,7 @@ do_open_directory (GnomeVFSMethod *metho
 		}
 	} 
 
-	result = end_transfer (conn);
+	result = end_transfer (conn, cancellation);
 
 	if(result != GNOME_VFS_OK) g_warning ("end_transfer (conn) failed!!!!");
 
@@ -1644,6 +1683,9 @@ do_move (GnomeVFSMethod *method,
 {
 	GnomeVFSResult result;
 	GnomeVFSFileInfo *p_file_info;
+	GnomeVFSCancellation *cancellation;
+	
+	cancellation = get_cancellation (context);
 
 	if (!force_replace) {
 		p_file_info = gnome_vfs_file_info_new ();
@@ -1665,11 +1707,11 @@ do_move (GnomeVFSMethod *method,
 		if (result != GNOME_VFS_OK) {
 			return result;
 		}
-		result = do_path_command (conn, "RNFR", old_uri);
+		result = do_path_command (conn, "RNFR", old_uri, cancellation);
 		
 		if (result == GNOME_VFS_OK) {
 			conn->fivefifty = GNOME_VFS_ERROR_ACCESS_DENIED;
-			result = do_path_command (conn, "RNTO", new_uri);
+			result = do_path_command (conn, "RNTO", new_uri, cancellation);
 			conn->fivefifty = GNOME_VFS_ERROR_NOT_FOUND;
 		}
 
Index: modules/http-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/http-method.c,v
retrieving revision 1.162
diff -u -p -r1.162 http-method.c
--- modules/http-method.c	4 Mar 2004 15:48:18 -0000	1.162
+++ modules/http-method.c	1 Apr 2004 13:23:56 -0000
@@ -607,7 +607,8 @@ parse_header (HttpFileHandle *handle,
 
 static GnomeVFSResult
 get_header (GnomeVFSSocketBuffer *socket_buffer,
-	    GString *s)
+	    GString *s,
+	    GnomeVFSCancellation *cancellation)
 {
 	GnomeVFSResult result;
 	GnomeVFSFileSize bytes_read;
@@ -623,7 +624,7 @@ get_header (GnomeVFSSocketBuffer *socket
 
 		/* ANALYZE_HTTP ("==> +get_header read"); */
 		result = gnome_vfs_socket_buffer_read (socket_buffer, &c, 1,
-				&bytes_read);
+						       &bytes_read, cancellation);
 		/* ANALYZE_HTTP ("==> -get_header read"); */
 
 		if (result != GNOME_VFS_OK) {
@@ -639,7 +640,7 @@ get_header (GnomeVFSSocketBuffer *socket
 				char next;
 
 				result = gnome_vfs_socket_buffer_peekc (
-						socket_buffer, &next);
+						socket_buffer, &next, cancellation);
 				if (result != GNOME_VFS_OK) {
 					return result;
 				}
@@ -678,17 +679,23 @@ create_handle (GnomeVFSURI *uri,
 	GString *header_string;
 	GnomeVFSResult result;
 	guint server_status;
+	GnomeVFSCancellation *cancellation;
 
 	g_return_val_if_fail (p_handle != NULL, GNOME_VFS_ERROR_INTERNAL);
 
 	*p_handle = http_file_handle_new (socket_buffer, uri);
 
+	cancellation = NULL;
+	if (context != NULL) {
+		cancellation = gnome_vfs_context_get_cancellation(context);
+	}
+	
 	header_string = g_string_new (NULL);
 
 	ANALYZE_HTTP ("==> +create_handle");
 
 	/* This is the status report string, which is the first header.  */
-	result = get_header (socket_buffer, header_string);
+	result = get_header (socket_buffer, header_string, cancellation);
 	if (result != GNOME_VFS_OK) {
 		goto error;
 	}
@@ -705,7 +712,7 @@ create_handle (GnomeVFSURI *uri,
 
 	/* Header fetching loop.  */
 	for (;;) {
-		result = get_header (socket_buffer, header_string);
+		result = get_header (socket_buffer, header_string, cancellation);
 		if (result != GNOME_VFS_OK) {
 			break;
 		}
@@ -1206,7 +1213,8 @@ https_proxy (GnomeVFSSocket **socket_ret
 	     gchar *proxy_host,
 	     gint proxy_port,
 	     gchar *server_host,
-	     gint server_port)
+	     gint server_port,
+	     GnomeVFSCancellation *cancellation)
 {
 	/* use CONNECT to do https proxying. It goes something like this:
 	 * >CONNECT server:port HTTP/1.0
@@ -1233,7 +1241,7 @@ https_proxy (GnomeVFSSocket **socket_ret
 	gint fd;
 
 	result = gnome_vfs_inet_connection_create (&http_connection, 
-			proxy_host, proxy_port, NULL);
+			proxy_host, proxy_port, cancellation);
 
 	if (result != GNOME_VFS_OK) {
 		return result;
@@ -1246,39 +1254,39 @@ https_proxy (GnomeVFSSocket **socket_ret
 	buffer = g_strdup_printf ("CONNECT %s:%d HTTP/1.0\r\n\r\n",
 			server_host, server_port);
 	result = gnome_vfs_socket_write (http_socket, buffer, strlen(buffer),
-			&bytes);
+					 &bytes, cancellation);
 	g_free (buffer);
 
 	if (result != GNOME_VFS_OK) {
-		gnome_vfs_socket_close (http_socket);
+		gnome_vfs_socket_close (http_socket, cancellation);
 		return result;
 	}
 
 	buffer = proxy_get_authn_header_for_uri (NULL); /* FIXME need uri */
 	if (buffer != NULL) {
 		result = gnome_vfs_socket_write (http_socket, buffer, 
-				strlen(buffer), &bytes);
+						 strlen(buffer), &bytes, cancellation);
 		g_free (buffer);
 	}
 
 	if (result != GNOME_VFS_OK) {
-		gnome_vfs_socket_close (http_socket);
+		gnome_vfs_socket_close (http_socket, cancellation);
 		return result;
 	}
 
 	bytes = 8192;
 	buffer = g_malloc0 (bytes);
 
-	result = gnome_vfs_socket_read (http_socket, buffer, bytes-1, &bytes);
+	result = gnome_vfs_socket_read (http_socket, buffer, bytes-1, &bytes, cancellation);
 
 	if (result != GNOME_VFS_OK) {
-		gnome_vfs_socket_close (http_socket);
+		gnome_vfs_socket_close (http_socket, cancellation);
 		g_free (buffer);
 		return result;
 	}
 
 	if (!parse_status (buffer, &status_code)) {
-		gnome_vfs_socket_close (http_socket);
+		gnome_vfs_socket_close (http_socket, cancellation);
 		g_free (buffer);
 		return GNOME_VFS_ERROR_PROTOCOL_ERROR;
 	}
@@ -1286,7 +1294,7 @@ https_proxy (GnomeVFSSocket **socket_ret
 	result = http_status_to_vfs_result (status_code);
 
 	if (result != GNOME_VFS_OK) {
-		gnome_vfs_socket_close (http_socket);
+		gnome_vfs_socket_close (http_socket, cancellation);
 		g_free (buffer);
 		return result;
 	}
@@ -1296,10 +1304,10 @@ https_proxy (GnomeVFSSocket **socket_ret
 
 	g_free (buffer);
 
-	result = gnome_vfs_ssl_create_from_fd (&ssl, fd);
+	result = gnome_vfs_ssl_create_from_fd (&ssl, fd, cancellation);
 
 	if (result != GNOME_VFS_OK) {
-		gnome_vfs_socket_close (http_socket);
+		gnome_vfs_socket_close (http_socket, cancellation);
 		return result;
 	}
 
@@ -1365,7 +1373,7 @@ connect_to_uri (
 			*p_proxy_connect = FALSE;
 
 			result = https_proxy (&socket, proxy_host, proxy_port,
-					toplevel_uri->host_name, host_port);
+					toplevel_uri->host_name, host_port, cancellation);
 
 			g_free (proxy_host);
 			proxy_host = NULL;
@@ -1395,7 +1403,7 @@ connect_to_uri (
 
 		if (https) {
 			result = gnome_vfs_ssl_create (&ssl, 
-					toplevel_uri->host_name, host_port);
+					toplevel_uri->host_name, host_port, cancellation);
 
 			if (result != GNOME_VFS_OK) {
 				return result;
@@ -1417,7 +1425,7 @@ connect_to_uri (
 	*p_socket_buffer = gnome_vfs_socket_buffer_new (socket);
 
 	if (*p_socket_buffer == NULL) {
-		gnome_vfs_socket_close (socket);
+		gnome_vfs_socket_close (socket, cancellation);
 		return GNOME_VFS_ERROR_INTERNAL;
 	}
 
@@ -1497,7 +1505,8 @@ build_request (const char * method, Gnom
 static GnomeVFSResult
 xmit_request (GnomeVFSSocketBuffer *socket_buffer, 
 	      GString *request, 
-	      GByteArray *data)
+	      GByteArray *data,
+	      GnomeVFSCancellation *cancellation)
 {
 	GnomeVFSResult result;
 	GnomeVFSFileSize bytes_written;
@@ -1506,7 +1515,8 @@ xmit_request (GnomeVFSSocketBuffer *sock
 
 	/* Transmit the request headers.  */
 	result = gnome_vfs_socket_buffer_write (socket_buffer, request->str, 
-			request->len, &bytes_written);
+						request->len, &bytes_written,
+						cancellation);
 
 	if (result != GNOME_VFS_OK) {
 		goto error;
@@ -1517,14 +1527,15 @@ xmit_request (GnomeVFSSocketBuffer *sock
 		ANALYZE_HTTP ("==> Writing data");
 		
 		result = gnome_vfs_socket_buffer_write (socket_buffer, 
-				data->data, data->len, &bytes_written);
+							data->data, data->len, &bytes_written,
+							cancellation);
 	}
 
 	if (result != GNOME_VFS_OK) {
 		goto error;
 	}
 
-	result = gnome_vfs_socket_buffer_flush (socket_buffer);	
+	result = gnome_vfs_socket_buffer_flush (socket_buffer, cancellation);	
 
 error:
 	return result;
@@ -1558,12 +1569,18 @@ make_request (HttpFileHandle **handle_re
 	char *authn_header_proxy;
 	gboolean first_auth;
 	HttpAuthSave *auth_save;
+	GnomeVFSCancellation *cancellation;
 	
 	g_return_val_if_fail (handle_return != NULL, GNOME_VFS_ERROR_INTERNAL);
  	*handle_return = NULL;
 
 	ANALYZE_HTTP ("==> +make_request");
 
+	cancellation = NULL;
+	if (context != NULL) {
+		cancellation = gnome_vfs_context_get_cancellation(context);
+	}
+	
 	request 		= NULL;
 	proxy_connect 		= FALSE;
 	authn_header_request	= NULL;
@@ -1632,7 +1649,7 @@ make_request (HttpFileHandle **handle_re
 		/* Empty line ends header section.  */
 		g_string_append (request, "\r\n");
 
-		result = xmit_request (socket_buffer, request, data);
+		result = xmit_request (socket_buffer, request, data, cancellation);
 		g_string_free (request, TRUE);
 		request = NULL;
 
@@ -1693,7 +1710,7 @@ make_request (HttpFileHandle **handle_re
 	}
 	
 	if (socket_buffer != NULL) {
-		gnome_vfs_socket_buffer_destroy (socket_buffer, TRUE);
+		gnome_vfs_socket_buffer_destroy (socket_buffer, TRUE, cancellation);
 	}
 	
 	ANALYZE_HTTP ("==> -make_request");
@@ -1704,13 +1721,20 @@ static void
 http_handle_close (HttpFileHandle *handle, 
 		   GnomeVFSContext *context)
 {
+	GnomeVFSCancellation *cancellation;
+	
 	ANALYZE_HTTP ("==> +http_handle_close");
 	
+	cancellation = NULL;
+	if (context != NULL) {
+		cancellation = gnome_vfs_context_get_cancellation(context);
+	}
+	
 	if (handle != NULL) {
 		if (handle->socket_buffer) {
-			gnome_vfs_socket_buffer_flush (handle->socket_buffer);
+			gnome_vfs_socket_buffer_flush (handle->socket_buffer, cancellation);
 			gnome_vfs_socket_buffer_destroy (handle->socket_buffer,
-							 TRUE);
+							 TRUE, cancellation);
 			handle->socket_buffer = NULL;
 		}
 
@@ -1931,10 +1955,17 @@ do_read (GnomeVFSMethod *method,
 {
 	HttpFileHandle *handle;
 	GnomeVFSResult result;
+	GnomeVFSCancellation *cancellation;
 
 	ANALYZE_HTTP ("==> +do_read");
 	DEBUG_HTTP (("+Read handle=0x%08x", (unsigned int) method_handle));
 
+	cancellation = NULL;
+	if (context != NULL) {
+		cancellation = gnome_vfs_context_get_cancellation(context);
+	}
+
+	
 	handle = (HttpFileHandle *) method_handle;
 
 	if (handle->file_info->flags & GNOME_VFS_FILE_INFO_FIELDS_SIZE) {
@@ -1945,7 +1976,7 @@ do_read (GnomeVFSMethod *method,
 	}
 
 	result = gnome_vfs_socket_buffer_read (handle->socket_buffer, buffer, 
-			num_bytes, bytes_read);
+					       num_bytes, bytes_read, cancellation);
 	
 	if (*bytes_read == 0) {
 		return GNOME_VFS_ERROR_EOF;
Index: modules/nntp-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/nntp-method.c,v
retrieving revision 1.6
diff -u -p -r1.6 nntp-method.c
--- modules/nntp-method.c	5 Feb 2004 13:01:47 -0000	1.6
+++ modules/nntp-method.c	1 Apr 2004 13:23:56 -0000
@@ -169,7 +169,7 @@ static GnomeVFSResult read_response_line
 		/* we don't have a full line. Lets read some... */
 		bytes_read = 0;
 		result = gnome_vfs_socket_buffer_read (conn->socketbuf, buf,
-						       bytes, &bytes_read);
+						       bytes, &bytes_read, NULL);
 		buf[bytes_read] = '\0';
 		conn->response_buffer = g_string_append (conn->response_buffer,
 							 buf);
@@ -243,8 +243,9 @@ static GnomeVFSResult do_control_write (
         char *actual_command = g_strdup_printf ("%s\r\n", command);
 	GnomeVFSFileSize bytes = strlen (actual_command), bytes_written;
 	GnomeVFSResult result = gnome_vfs_socket_buffer_write (conn->socketbuf,
-							       actual_command, bytes, &bytes_written);
-	gnome_vfs_socket_buffer_flush (conn->socketbuf);
+							       actual_command, bytes, &bytes_written,
+							       NULL);
+	gnome_vfs_socket_buffer_flush (conn->socketbuf, NULL);
 	g_free (actual_command);
 
 	return result;
@@ -369,7 +370,7 @@ nntp_connection_create (NNTPConnection *
 			/* login failed */
 			g_warning ("NNTP server said: \"%d %s\"\n", conn->response_code,
 			   	conn->response_message);
-			gnome_vfs_socket_buffer_destroy (conn->socketbuf, FALSE);
+			gnome_vfs_socket_buffer_destroy (conn->socketbuf, FALSE, context ? gnome_vfs_context_get_cancellation(context) : NULL);
 			gnome_vfs_inet_connection_destroy (conn->inet_connection, NULL);
 			g_free (conn);
 			return result;
@@ -395,7 +396,7 @@ nntp_connection_destroy (NNTPConnection 
 	}
 	
 	if (conn->socketbuf) 
-	        gnome_vfs_socket_buffer_destroy (conn->socketbuf, FALSE);
+	        gnome_vfs_socket_buffer_destroy (conn->socketbuf, FALSE, NULL);
 
 	gnome_vfs_uri_unref (conn->uri);
 
Index: test/test-ssl.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/test/test-ssl.c,v
retrieving revision 1.4
diff -u -p -r1.4 test-ssl.c
--- test/test-ssl.c	3 Aug 2001 19:04:43 -0000	1.4
+++ test/test-ssl.c	1 Apr 2004 13:23:56 -0000
@@ -92,7 +92,7 @@ main (int argc, char **argv)
 	}
 	g_print (".\n");
 
-	result = gnome_vfs_ssl_create (&ssl, host, port);
+	result = gnome_vfs_ssl_create (&ssl, host, port, NULL);
 
 	show_result (result, "ssl_create", host, port);
 
@@ -121,17 +121,20 @@ main (int argc, char **argv)
 	switch (abstraction) {
 		case SSL:
 			result = gnome_vfs_ssl_write (ssl, HTTP_REQUEST, 
-					strlen(HTTP_REQUEST), &bytes_read);
+						      strlen(HTTP_REQUEST), &bytes_read,
+						      NULL);
 			break;
 		case SOCKET:
 			result = gnome_vfs_socket_write (socket, HTTP_REQUEST, 
-					strlen(HTTP_REQUEST), &bytes_read);
+							 strlen(HTTP_REQUEST), &bytes_read,
+							 NULL);
 			break;
 		case SOCKETBUFFER:
 			result = gnome_vfs_socket_buffer_write (socketbuffer,
-					HTTP_REQUEST, strlen(HTTP_REQUEST),
-					&bytes_read);
-			gnome_vfs_socket_buffer_flush (socketbuffer);
+								HTTP_REQUEST, strlen(HTTP_REQUEST),
+								&bytes_read,
+								NULL);
+			gnome_vfs_socket_buffer_flush (socketbuffer, NULL);
 			break;
 	}
 
@@ -141,16 +144,19 @@ main (int argc, char **argv)
 		switch (abstraction) {
 			case SSL:
 				result = gnome_vfs_ssl_read (ssl, buffer, 
-						sizeof buffer - 1, &bytes_read);
+							     sizeof buffer - 1, &bytes_read,
+							     NULL);
 				break;
 			case SOCKET:
 				result = gnome_vfs_socket_read (socket, buffer, 
-						sizeof buffer - 1, &bytes_read);
+								sizeof buffer - 1, &bytes_read,
+								NULL);
 				break;
 			case SOCKETBUFFER:
 				result = gnome_vfs_socket_buffer_read (
 						socketbuffer, buffer, 
-						sizeof buffer - 1, &bytes_read);
+						sizeof buffer - 1, &bytes_read,
+						NULL);
 				break;
 		}
 		show_result (result, "read", host, port);
@@ -162,13 +168,13 @@ main (int argc, char **argv)
 
 	switch (abstraction) {
 		case SSL:
-			gnome_vfs_ssl_destroy (ssl);
+			gnome_vfs_ssl_destroy (ssl, NULL);
 			break;
 		case SOCKET:
-			gnome_vfs_socket_close (socket);
+			gnome_vfs_socket_close (socket, NULL);
 			break;
 		case SOCKETBUFFER:
-			gnome_vfs_socket_buffer_destroy (socketbuffer, TRUE);
+			gnome_vfs_socket_buffer_destroy (socketbuffer, TRUE, NULL);
 			break;
 	}
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]