[axel-commits] r69 - in /branches/3.x-broken: doc/ROADMAP src/conn.c src/conn.h src/proto.h

phihag-guest at users.alioth.debian.org phihag-guest at users.alioth.debian.org
Mon Dec 22 11:14:07 UTC 2008


Author: phihag-guest
Date: Mon Dec 22 11:14:07 2008
New Revision: 69

URL: http://svn.debian.org/wsvn/axel/?sc=1&rev=69
Log:
Some more work on threading code

Modified:
    branches/3.x-broken/doc/ROADMAP
    branches/3.x-broken/src/conn.c
    branches/3.x-broken/src/conn.h
    branches/3.x-broken/src/proto.h

Modified: branches/3.x-broken/doc/ROADMAP
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/doc/ROADMAP?rev=69&op=diff
==============================================================================
--- branches/3.x-broken/doc/ROADMAP (original)
+++ branches/3.x-broken/doc/ROADMAP Mon Dec 22 11:14:07 2008
@@ -15,9 +15,9 @@
 
 * Parse Content-Disposition header (#311101)
  Look if the specific problem mentioned in the bug is fixed by this.
-* Do not rerequest != 20x more than once
+* Do not rerequest HTTP code  != 20x more than once
 * Exponential backoff, exponential backoff, and make sure to include exponential backoff
-* readd proxy support
+* re-add proxy support
 
 
 Code structure

Modified: branches/3.x-broken/src/conn.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/conn.c?rev=69&op=diff
==============================================================================
--- branches/3.x-broken/src/conn.c (original)
+++ branches/3.x-broken/src/conn.c Mon Dec 22 11:14:07 2008
@@ -25,8 +25,49 @@
 
 #include "axel.h"
 
-/* TODO Remove this */
-char string[MAX_STRING];
+static void conn_start_threadstart(void* conn);
+
+void conn_init(conn_t *c, const url_t* url, const conf_t* conf, long long startbyte, long long endbyte) {
+	c->conf = conf;
+	c->url = url;
+	
+	proto_init(c->proto, url->protoid);
+	c->currentbyte = startbyte;
+	c->endbyte = endbyte;
+	c->cstate = INITIALIZED;
+	c->message = NULL;
+}
+
+void conn_start(conn_t* c) {
+	if (pthread_create(conn->thread, NULL, conn_threadstart, c) != 0) {
+		// TODO pthread error
+	}
+	
+}
+
+// Entry point for the created thread
+void conn_threadstart(void* conn_void) {
+	conn_t* conn = conn_void;
+	int oldstate; // Dummy
+	
+	if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate) != 0) ||
+		(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate) != 0)) {
+		
+		conn->message = _("Thread initialization failed");
+		conn->cstate = ERROR;
+		return;
+	}
+	
+	
+}
+
+// Reads all headers, blocks until read. cstate is guaranteed to be either DOWNLOADING or FINISHED afterwards.
+void conn_readheaders(conn_t* conn);
+// Read up to bufsize bytes from this connection into buf. Segmantics are same as for the POSIX read() call.
+ssize_t conn_read(conn_t* conn, char* buf, size_t bufsize);
+void conn_destroy(conn_t* conn);
+
+
 
 /* Convert an URL to a conn_t structure					*/
 int conn_set( conn_t *conn, char *set_url )

Modified: branches/3.x-broken/src/conn.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/conn.h?rev=69&op=diff
==============================================================================
--- branches/3.x-broken/src/conn.h (original)
+++ branches/3.x-broken/src/conn.h Mon Dec 22 11:14:07 2008
@@ -23,6 +23,8 @@
   Suite 330, Boston, MA  02111-1307  USA
 */
 
+#define CONNB_UNKWOWN (-1)
+
 enum connstate {
 	INITIALIZED, // Just initialized
 	REQUESTED, // First byte went out to the network
@@ -32,24 +34,33 @@
 };
 
 typedef struct {
-	conf_t *conf;
+	const conf_t *conf;
 	
-	url_t* url; /* The URL to download from. Not owned by this struct */
-	proto_t* proto;
+	const url_t* url; /* The URL to download from. Not owned by this struct */
+	proto_t[1] proto;
 	
-	long long currentbyte;
-	long long lastbyte;
+	long long currentbyte; // The index of the byte we're currently reading, starting with zero.
+	long long lastbyte; // The zero-based index of the last byte we should read. CONNB_UNKWOWN if everything should be read.
 	
-	int fd;
-	int enabled;
-	int supported;
-	int last_transfer;
-	
-	connstate cstate;
+	volatile connstate cstate;
 	char *message;
 	
-	pthread_t thread[1];
+	// Must only be read from other modules while cstate == DOWNLOADING
+	int fd;
+	
+	// The following header settings are only set if state in {DOWNLOADING,FINISHED}
+	long long segsize; // Size of the whole segment we're downloading, CONNB_UNKWOWN if unknown
+	_Bool resume_supported; // 1 iff the server we're downloading from allows ranged downloading.
+	
+	// The thread that handles this connection. Only defined while connstate in {INITIALIZED, REQUESTED}
+	pthread_t[1] thread;
 } conn_t;
 
-void conn_init(conn_t *conn, url_t* url, conf_t* conf, long long startbyte, long long endbyte);
-
+void conn_init(conn_t *conn, const url_t* url, const conf_t* conf, long long startbyte, long long endbyte);
+// Start a thread that initiates downloading
+void conn_start(conn_t* conn);
+// Reads all headers, blocks until read. cstate is guaranteed to be either DOWNLOADING or FINISHED afterwards.
+void conn_readheaders(conn_t* conn);
+// Read up to bufsize bytes from this connection into buf. Segmantics are same as for the POSIX read() call.
+ssize_t conn_read(conn_t* conn, char* buf, size_t bufsize);
+void conn_destroy(conn_t* conn);

Modified: branches/3.x-broken/src/proto.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/proto.h?rev=69&op=diff
==============================================================================
--- branches/3.x-broken/src/proto.h (original)
+++ branches/3.x-broken/src/proto.h Mon Dec 22 11:14:07 2008
@@ -35,7 +35,8 @@
 	/* TODO include a number of callbacks here, including a free-this-struct one */
 } proto_t;
 
-proto_t* proto_new(int protoid);
+proto_t proto_init(proto_t*, int protoid);
+proto_t proto_destroy(proto_t*);
 
 int proto_defport(int protoid);
 int proto_getid(const char* protostr);




More information about the axel-commits mailing list