socsvn commit: r256166 - soc2013/ambarisha/head/usr.bin/dms

ambarisha at FreeBSD.org ambarisha at FreeBSD.org
Mon Aug 19 20:44:03 UTC 2013


Author: ambarisha
Date: Mon Aug 19 20:44:02 2013
New Revision: 256166
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256166

Log:
  Worker sends status updates to client
  

Modified:
  soc2013/ambarisha/head/usr.bin/dms/worker.c

Modified: soc2013/ambarisha/head/usr.bin/dms/worker.c
==============================================================================
--- soc2013/ambarisha/head/usr.bin/dms/worker.c	Mon Aug 19 20:41:32 2013	(r256165)
+++ soc2013/ambarisha/head/usr.bin/dms/worker.c	Mon Aug 19 20:44:02 2013	(r256166)
@@ -23,17 +23,8 @@
 {
 	struct dmmsg msg;
 	struct dmjob *cur = jobs;
-	while (cur != NULL) {
-		/* TODO: May be a more thorough comparison? */
-		if (cur->url == url)
-			break;
-		cur = cur->next;
-	}
-
-	if (cur == NULL)
-		return -1; // Todo: Verify this
-
 	int bufsize = 0, i = 0, schlen, hlen;
+
 	schlen = strlen(url->scheme) + 1;
 	hlen = strlen(url->host) + 1;
 	bufsize += schlen + hlen + sizeof(url->port);
@@ -54,24 +45,22 @@
 
 	msg.op = DMAUTHREQ;
 	msg.len = bufsize;
-	ret = send_dmmsg(cur->client, msg);
-	if (ret == -1) {
-		free(msg.buf);
-		return -1;
-	}
 
-	struct dmmsg *rcvmsg;
-	rcvmsg = recv_dmmsg(cur->client);
-	if (rcvmsg == NULL) { 
-		free(msg.buf);
-		return -1;
-	}
+	while (cur != NULL) {
+		/* TODO: May be a more thorough comparison? */
+		if (cur->url != url) {
+			cur = cur->next;
+			continue;
+		}
 
-	strncpy(url->user, rcvmsg->buf, sizeof(url->user));
-	strncpy(url->pwd, rcvmsg->buf + strlen(rcvmsg->buf) + 1, sizeof(url->pwd));
-	free_dmmsg(&rcvmsg);
+		
+		/* TODO: How do we figure out which request's 
+		 * authentication credentials to use ???
+		 * */
 
-	return 1; // TODO: Verify this 
+	}
+
+	return 1;
 }
 
 static int
@@ -81,8 +70,12 @@
 }
 
 static void
-stat_send(int csock, struct xferstat *xs, int force)
+stat_send(struct xferstat *xs, int force)
 {
+	struct dmjob *cur;
+	struct dmmsg msg;
+	pthread_t  self = pthread_self();
+
 	char *buf = (char *) malloc(sizeof(struct xferstat) + sizeof(force));
 	if (buf == NULL) {
 		fprintf(stderr,  "stat_send: Insufficient memory\n");
@@ -93,11 +86,17 @@
 	
 	memcpy(buf + sizeof(force), xs, sizeof(struct xferstat));
 
-	struct dmmsg msg;
 	msg.op = DMSTAT;
 	msg.buf = buf; 
 	msg.len = sizeof(*xs) + sizeof(force);
-	send_dmmsg(csock, msg);
+	cur = jobs;
+
+	while (cur != NULL) {
+		if (pthread_equal(self, cur->worker) != 0)	
+			send_dmmsg(cur->client, msg);
+		cur = cur->next;
+	}
+
 	free(buf);
 	return;
 }
@@ -146,7 +145,7 @@
 	xs->rcvd = offset;
 	xs->lastrcvd = offset;
 	if ((dmjob->request->flags & V_TTY) && dmjob->request->v_level > 0)
-		stat_send(dmjob->client, xs, 1);
+		stat_send(xs, 1);
 	else if (dmjob->request->v_level > 0)
 		fprintf(stderr, "%-46s", xs->name);
 }
@@ -156,7 +155,7 @@
 {
 	gettimeofday(&xs->last, NULL);
 	if ((dmjob->request->flags & V_TTY) && dmjob->request->v_level > 0) {
-		stat_send(dmjob->client, xs, 2);
+		stat_send(xs, 2);
 		putc('\n', stderr);
 	} else if (dmjob->request->v_level > 0) {
 		fprintf(stderr, "        %s %s\n",
@@ -169,7 +168,7 @@
 {
 	xs->rcvd = rcvd;
 	if ((dmjob->request->flags & V_TTY) && dmjob->request->v_level > 0)
-		stat_send(dmjob->client, xs, 0);
+		stat_send(xs, 0);
 }
 
 static int
@@ -815,6 +814,8 @@
 		tmp = tmp->next;
 	}
 
+	dmjob->worker = pthread_self();
+
 	/* fetch the remote file into a local tmp file */
 	f = dmXGet(dmjob, &us);
 


More information about the svn-soc-all mailing list