Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Aug 2007 10:48:52 GMT
From:      Matus Harvan <mharvan@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 124890 for review
Message-ID:  <200708081048.l78Amq8W031547@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=124890

Change 124890 by mharvan@mharvan_bike-planet on 2007/08/08 10:48:32

	TCP plugin should send the packet length and the packet itself in one go

Affected files ...

.. //depot/projects/soc2007/mharvan-mtund/mtund.src/plugin_tcp.c#9 edit

Differences ...

==== //depot/projects/soc2007/mharvan-mtund/mtund.src/plugin_tcp.c#9 (text+ko) ====

@@ -328,21 +328,30 @@
 int plugin_send(plugint *pl, char *data, int len, int data_type) {
     plugin_tcp_datat *datapl = (plugin_tcp_datat*) pl->data;
     int n = 0;
+    char *ldata;
 
     if (datapl->state != PLUGIN_STATE_CONNECTED) {
 	fprintf(stderr, "no client connected yet, discarding data\n");
 	return 0;
     } else {
+	ldata = malloc(len+sizeof(len));
+	if (ldata == NULL)
+	    return (SEND_ERROR_MALLOC);
+	memcpy(ldata, &len, sizeof(len));
+	memcpy(ldata + sizeof(len), data, len);
+	n = write(datapl->fd, ldata, sizeof(len) + len);
+	free(ldata);
+	
 	//n = write(datapl->fd, data, len);
-	// TODO: we should use on buffer only as the current
+	// TODO: we should use one buffer only as the current
 	//       approach generates two packets
-	n = send(datapl->fd, &len, sizeof(len), 0);
-	n = send(datapl->fd, data, len, 0);
+	//n = send(datapl->fd, &len, sizeof(len), 0);
+	//n = send(datapl->fd, data, len, 0);
 	//fprintf(stderr, "plugin_send: fd: %d\n", datapl->fd);
 	//fprintf(stderr, "plugin_send: write returned %d\n", n);
     }
     if (n < 0 || (len != 0 && n == 0) ) {
-	plugin_report(pl, REPORT_ERROR_RECEIVE);
+	plugin_report(pl, REPORT_ERROR_SEND);
     }
     //return n;
     return SEND_PKT_SENT;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708081048.l78Amq8W031547>