[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r14150 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r14150 - gnunet/src/transport |
Date: |
Wed, 12 Jan 2011 00:38:54 +0100 |
Author: brodski
Date: 2011-01-12 00:38:54 +0100 (Wed, 12 Jan 2011)
New Revision: 14150
Modified:
gnunet/src/transport/gnunet-transport-wlan-helper.c
gnunet/src/transport/plugin_transport_wlan.c
gnunet/src/transport/test_plugin_transport_wlan_dummy.c
Log:
Modified: gnunet/src/transport/gnunet-transport-wlan-helper.c
===================================================================
--- gnunet/src/transport/gnunet-transport-wlan-helper.c 2011-01-11 15:29:42 UTC
(rev 14149)
+++ gnunet/src/transport/gnunet-transport-wlan-helper.c 2011-01-11 23:38:54 UTC
(rev 14150)
@@ -415,21 +415,48 @@
}
}
+struct sendbuf{
+ int pos;
+ int size;
+ char buf[MAXLINE * 2];
+};
+static void
+stdin_send (void *cls,
+ void *client,
+ const struct GNUNET_MessageHeader *hdr)
+{
+ struct sendbuf *write_pout = cls;
+ GNUNET_assert (hdr->size + write_pout->size < MAXLINE *2);
+ memcpy(write_pout->buf + write_pout->size, hdr, hdr->size);
+ write_pout->size += hdr->size;
+}
+static void
+file_in_send (void *cls,
+ void *client,
+ const struct GNUNET_MessageHeader *hdr)
+{
+ struct sendbuf * write_std = cls;
+ GNUNET_assert (hdr->size + write_std->size < MAXLINE *2);
+ memcpy(write_std->buf + write_std->size, hdr, hdr->size);
+ write_std->size += hdr->size;
+}
+
int
testmode(int argc, char *argv[])
{
struct stat st;
int erg;
- int fd[2];
FILE *fpin;
FILE *fpout;
- pid_t pid;
+ int fdpin;
+ int fdpout;
+
//make the fifos if needed
if (stat(FIFO_FILE1, &st) != 0)
{
@@ -438,188 +465,242 @@
perror("FIFO 2 exists, but FIFO 1 not");
exit(1);
}
- first = 1;
+
umask(0);
erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
- if ((fpin = fopen(FIFO_FILE1, "r")) == NULL)
- {
- perror("fopen");
- exit(1);
- }
- if ((fpout = fopen(FIFO_FILE2, "w")) == NULL)
- {
- perror("fopen");
- exit(1);
- }
+
}
else
{
- first = 0;
+
if (stat(FIFO_FILE2, &st) != 0)
{
perror("FIFO 1 exists, but FIFO 2 not");
exit(1);
}
- if ((fpout = fopen(FIFO_FILE1, "w")) == NULL)
- {
- perror("fopen");
- exit(1);
- }
- if ((fpin = fopen(FIFO_FILE2, "r")) == NULL)
- {
- perror("fopen");
- exit(1);
- }
+
}
- // fork
+ if (strstr(argv[2],"1")) {
+ first = 1;
+ fpin = fopen(FIFO_FILE1, "r");
+ if (fpin == NULL)
+ {
+ perror("fopen");
+ exit(1);
+ }
+ if ((fpout = fopen(FIFO_FILE2, "w")) == NULL)
+ {
+ perror("fopen");
+ exit(1);
+ }
- fd[0] = STDIN_FILENO;
- fd[1] = STDOUT_FILENO;
+ } else {
+ first = 0;
+ if ((fpout = fopen(FIFO_FILE1, "w")) == NULL)
+ {
+ perror("fopen");
+ exit(1);
+ }
+ if ((fpin = fopen(FIFO_FILE2, "r")) == NULL)
+ {
+ perror("fopen");
+ exit(1);
+ }
- if ((pid = fork()) < 0)
- {
- perror("FORK ERROR");
- //clean up
- if (first == 1)
- {
- unlink(FIFO_FILE1);
- unlink(FIFO_FILE2);
- }
- fclose(fpin);
- fclose(fpout);
- return -3;
- }
- else if (pid == 0) // CHILD PROCESS
- {
+ }
- signal(SIGINT, sigfunc);
- signal(SIGTERM, sigfunc);
- signal(SIGKILL, sigfunc);
- int rv = 0;
- int readc = 0;
- int pos = 0;
- char line[MAXLINE];
- int ret = 0;
+ fdpin = fileno(fpin);
+ fdpout = fileno(fpout);
- while (closeprog == 0)
- {
- readc = 0;
+ signal(SIGINT, sigfunc);
+ signal(SIGTERM, sigfunc);
+ signal(SIGKILL, sigfunc);
- //while (readc < sizeof( struct RadiotapHeader) + sizeof(struct
GNUNET_MessageHeader)){
- if ((rv = read(fd[0], line, MAXLINE)) < 0)
- {
- perror("READ ERROR FROM STDIN");
- }
- readc += rv;
- //}
+ char readbuf[MAXLINE];
+ int readsize = 0;
+ struct sendbuf write_std;
+ write_std.size = 0;
+ write_std.pos = 0;
- if (closeprog == 1){
- break;
- }
+ struct sendbuf write_pout;
+ write_pout.size = 0;
+ write_pout.pos = 0;
- pos = 0;
+ int ret = 0;
+ int maxfd = 0;
+ int to_write_stdout = 0;
+ int to_write_fpout = 0;
+ fd_set rfds;
+ fd_set wfds;
+ struct timeval tv;
+ int retval;
- perror("writing blub");
- //fwrite(&line[pos], 1, sizeof(struct GNUNET_MessageHeader), fpout);
- //pos += sizeof(struct GNUNET_Mes#include
"gnunet_util_lib.h"sageHeader);
- //do not send radiotap header
- //pos += sizeof( struct RadiotapHeader);
+ maxfd = MAX(fdpout, fdpin);
+ maxfd = MAX(maxfd, STDOUT_FILENO);
+ maxfd++;
- while (pos < readc)
- {
- ret = fwrite(&line[pos], 1, readc - pos, fpout);
- if (ret < 0)
- {
- closeprog = 1;
- perror("Write ERROR FROM fpout");
- break;
- }
- else
- {
- pos += ret;
- }
- }
- }
+ struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
+ struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
+ stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout);
+ file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std);
- //clean up
- fclose(fpout);
- }
- else // PARENT PROCESS
+ //send mac first
+
+ struct Wlan_Helper_Control_Message macmsg;
+
+ //Send random mac address
+ macmsg.mac.mac[0] = 0x13;
+ macmsg.mac.mac[1] = 0x22;
+ macmsg.mac.mac[2] = 0x33;
+ macmsg.mac.mac[3] = 0x44;
+ macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
255);
+ macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
255);
+ macmsg.hdr.size = sizeof(struct Wlan_Helper_Control_Message);
+ macmsg.hdr.type = GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL;
+
+ memcpy(&write_std.buf, &macmsg, macmsg.hdr.size);
+ write_std.size = macmsg.hdr.size;
+
+
+ while (closeprog == 0)
{
- signal(SIGINT, sigfunc);
- signal(SIGTERM, sigfunc);
- signal(SIGKILL, sigfunc);
- int rv = 0;
- int ret = 0;
- ssize_t pos = 0;
- char line[MAXLINE];
- struct Wlan_Helper_Control_Message macmsg;
- //Send random mac address
- macmsg.mac.mac[0] = 0x13;
- macmsg.mac.mac[1] = 0x22;
- macmsg.mac.mac[2] = 0x33;
- macmsg.mac.mac[3] = 0x44;
- macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
255);
- macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
255);
- macmsg.hdr.size = sizeof(struct Wlan_Helper_Control_Message);
- macmsg.hdr.type = GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL;
+ //set timeout
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
- pos = 0;
+ FD_ZERO(&rfds);
+ // if output queue is emty
+ if (to_write_fpout == 0)
+ FD_SET(STDIN_FILENO, &rfds);
+ if (to_write_stdout == 0)
+ FD_SET(fdpin, &rfds);
- while (pos < sizeof(struct Wlan_Helper_Control_Message))
+ FD_ZERO(&wfds);
+ // if there is something to write
+ if (to_write_stdout > 0)
+ FD_SET(STDOUT_FILENO, &wfds);
+ if (to_write_fpout > 0)
+ FD_SET(fdpout, &wfds);
+
+ retval = select(maxfd, &rfds, &wfds, NULL, &tv);
+
+
+ if (retval == -1 && errno == EINTR){
+ continue;
+ }
+ if (retval < 0){
+ perror("select()");
+ exit(1);
+ }
+
+ if (FD_ISSET(STDOUT_FILENO, &wfds))
{
- pos += write(fd[1], &macmsg + pos, sizeof(struct
Wlan_Helper_Control_Message) - pos);
+ ret = write(STDOUT_FILENO, write_std.buf + write_std.pos,
+ write_std.size - write_std.pos);
+
+ if (ret < 0)
+ {
+ closeprog = 1;
+ perror("Write ERROR to STDOUT");
+ exit(1);
+ }
+ else
+ {
+ write_std.pos += ret;
+ // check if finished
+ if (write_std.pos == write_std.size)
+ {
+ write_std.pos = 0;
+ write_std.size = 0;
+ }
+ }
}
- while (closeprog == 0)
+ if (FD_ISSET(fdpout, &wfds))
{
- if ((rv = fread(line, 1, MAXLINE, fpin)) < 0)
+ ret = write(fdpout, write_pout.buf + write_pout.pos,
+ write_pout.size - write_pout.pos);
+
+ if (ret < 0)
{
- perror("READ ERROR FROM fpin");
+ closeprog = 1;
+ perror("Write ERROR to fdpout");
+ exit(1);
}
- if (closeprog == 1){
- break;
- }
- pos = 0;
- while (pos < rv)
+ else
{
-
- ret= write(fd[1], &line[pos], rv - pos);
- if (ret < 0)
+ write_pout.pos += ret;
+ // check if finished
+ if (write_pout.pos == write_pout.size)
{
- closeprog = 1;
- perror("Write ERROR FROM STDout");
- break;
+ write_pout.pos = 0;
+ write_pout.size = 0;
}
- else
- {
- pos += ret;
- }
}
}
+ if (FD_ISSET(STDIN_FILENO, &rfds))
+ {
+ readsize = read(STDIN_FILENO, readbuf,
+ sizeof(readbuf));
+ if (readsize < 0)
+ {
+ closeprog = 1;
+ perror("Write ERROR to STDIN_FILENO");
+ exit(1);
+ }
+ else
+ {
+ GNUNET_SERVER_mst_receive(stdin_mst, NULL,
+ readbuf, readsize, GNUNET_NO, GNUNET_NO);
+
+ }
+ }
+
+ if (FD_ISSET(fdpin, &rfds))
+ {
+ readsize = read(fdpin, readbuf,
+ sizeof(readbuf));
+
+ if (readsize < 0)
+ {
+ closeprog = 1;
+ perror("Write ERROR to STDIN_FILENO");
+ exit(1);
+ }
+ else
+ {
+ GNUNET_SERVER_mst_receive(file_in_mst, NULL,
+ readbuf, readsize, GNUNET_NO, GNUNET_NO);
+
+ }
+ }
+
+
+ }
+
//clean up
+ fclose(fpout);
fclose(fpin);
+ perror("Write ERROR to STDIN_FILENO");
if (first == 1)
{
unlink(FIFO_FILE1);
unlink(FIFO_FILE2);
}
- }
- // Write the input to the output
return (0);
}
@@ -628,10 +709,14 @@
int
main(int argc, char *argv[])
{
- if ((argc==2) && (strstr(argv[1],"1")))
- {
- return testmode(argc, argv);
- }
+ if (argc == 3)
+ {
+ if (strstr(argv[2], "1") || strstr(argv[2], "2"))
+ {
+
+ return testmode(argc, argv);
+ }
+ }
#if 0
u8 u8aSendBuffer[500];
char szErrbuf[PCAP_ERRBUF_SIZE];
Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c 2011-01-11 15:29:42 UTC
(rev 14149)
+++ gnunet/src/transport/plugin_transport_wlan.c 2011-01-11 23:38:54 UTC
(rev 14150)
@@ -2008,6 +2008,8 @@
#endif
/* Start the server process */
+ //if (testmode == 0){
+
plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin,
plugin->server_stdout, filename,filename, plugin->interface,
((testmode==1)?"1":"0"), NULL);
if (plugin->server_proc == NULL)
@@ -2018,6 +2020,13 @@
#endif
return GNUNET_SYSERR;
}
+ //} else if (testmode == 1){
+
+
+ //} else if (testmode == 2){
+
+
+ //}
/* Close the write end of the read pipe */
GNUNET_DISK_pipe_close_end(plugin->server_stdout,
GNUNET_DISK_PIPE_END_WRITE);
Modified: gnunet/src/transport/test_plugin_transport_wlan_dummy.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_wlan_dummy.c 2011-01-11
15:29:42 UTC (rev 14149)
+++ gnunet/src/transport/test_plugin_transport_wlan_dummy.c 2011-01-11
23:38:54 UTC (rev 14150)
@@ -56,6 +56,7 @@
+
int
main(int argc, char *argv[])
{
@@ -144,10 +145,33 @@
int pos = 0;
char line[MAXLINE];
+ fd_set rfds;
+ fd_set wfds;
+ struct timeval tv;
+ int retval;
+
+
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+
+
+ FD_ZERO(&rfds);
+ FD_SET(STDIN_FILENO, &rfds);
+
+ FD_ZERO(&wfds);
+ FD_SET(STDOUT_FILENO, &wfds);
+
+ struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
+ struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
+
+ stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, NULL);
+ file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, NULL);
+
while (closeprog == 0)
{
readc = 0;
+
while (readc < sizeof( struct RadiotapHeader) + sizeof(struct
GNUNET_MessageHeader)){
if ((rv = read(STDIN_FILENO, line, MAXLINE)) < 0)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r14150 - gnunet/src/transport,
gnunet <=