diff --git a/Makefile b/Makefile index 818f1fc..5de63bd 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ FFTW_PACKAGE = fftw-3.3.3 .PHONY: clean-vect clean all: csdr ddcd -libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c +libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c *.h @echo NOTE: you may have to manually edit Makefile to optimize for your CPU \(especially if you compile on ARM, please edit PARAMS_NEON\). @echo Auto-detected optimization parameters: $(PARAMS_SIMD) @echo @@ -54,8 +54,8 @@ libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c -./parsevect dumpvect*.vect csdr: csdr.c libcsdr.so gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) csdr.c $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o csdr -ddcd: ddcd.c libcsdr.so - gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) ddcd.c $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o ddcd +ddcd: ddcd.cpp libcsdr.so ddcd.h + g++ $(PARAMS_LOOPVECT) $(PARAMS_SIMD) ddcd.cpp $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o ddcd arm-cross: clean-vect #note: this doesn't work since having added FFTW arm-linux-gnueabihf-gcc -std=gnu99 -O3 -fshort-double -ffast-math -dumpbase dumpvect-arm -fdump-tree-vect-details -mfloat-abi=softfp -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mvectorize-with-neon-quad -Wno-unused-result -Wformat=0 $(SOURCES) -lm -o ./csdr diff --git a/ddcd.c b/ddcd.cpp similarity index 66% rename from ddcd.c rename to ddcd.cpp index 5dd0bd1..d6d9403 100644 --- a/ddcd.c +++ b/ddcd.cpp @@ -28,19 +28,28 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "ddcd.h" #include #include #include #include #include +#include +#include +#include +#include +#include +#include #define SOFTWARE_NAME "ddcd" #define MSG_START SOFTWARE_NAME ": " -struct client_s +typedef struct client_s { + struct sockaddr_in addr; int socket; - int addr; + pid_t pid; + int pipefd[2]; } client_t; int host_port = 0; @@ -51,9 +60,6 @@ int main(int argc, char* argv[]) { int c; - //arguments: - - for(;;) { int option_index = 0; @@ -87,14 +93,58 @@ int main(int argc, char* argv[]) if(!decimation) { fprintf(stderr, MSG_START "missing required command line argument, --decimation.\n"); exit(1); } if(!host_port) { fprintf(stderr, MSG_START "missing required command line argument, --port.\n"); exit(1); } - /*struct sockaddr_in addr_host; + struct sockaddr_in addr_host; int listen_socket; - std::vector clients; + std::vector clients(10); listen_socket=socket(AF_INET,SOCK_STREAM,0); memset(&addr_host,'0',sizeof(addr_host)); addr_host.sin_family=AF_INET; - addr_host.sin_port=htons(8888); - addr_host.sin_addr.s_addr=inet_addr("127.0.0.1"); - */ - + addr_host.sin_port=htons(host_port); + + if( (addr_host.sin_addr.s_addr=inet_addr(host_address)) == INADDR_NONE) + { fprintf(stderr, MSG_START "invalid host address.\n"); exit(1); } + + if( bind(listen_socket, (struct sockaddr*) &addr_host, sizeof(addr_host)) < 0) + { fprintf(stderr, MSG_START "cannot bind() address to the socket.\n"); exit(1); } + + if( listen(listen_socket, 10) == -1) + { fprintf(stderr, MSG_START "cannot listen() on socket.\n"); exit(1); } + + for(;;) + { + struct sockaddr_in addr_cli; + socklen_t addr_cli_len; + int new_socket; + + if( (new_socket = accept(listen_socket, (struct sockaddr*)&addr_cli, &addr_cli_len)) == -1) + { + fprintf(stderr, MSG_START "cannot accept() a connection.\n"); + continue; + } + + client_t* new_client = new client_t; + memcpy(&new_client->addr, &addr_cli, sizeof(new_client->addr)); + new_client->socket = new_socket; + + if(new_client->pid = fork()) + { + //We're the parent + clients.push_back(new_client); + printf("client pid: %d\n", new_client->pid); + } + else + { + //We're the client + client(); + break; + } + } + + return 0; +} + +void client() +{ + printf("I'm the client\n"); + for(;;) sleep(1); } diff --git a/ddcd.h b/ddcd.h new file mode 100644 index 0000000..02ed196 --- /dev/null +++ b/ddcd.h @@ -0,0 +1 @@ +void client();