Working on the socket server now.

This commit is contained in:
ha7ilm 2015-11-04 13:31:47 +01:00
parent 7859ac9d39
commit 2b8101ddf6
3 changed files with 65 additions and 14 deletions

View file

@ -45,7 +45,7 @@ FFTW_PACKAGE = fftw-3.3.3
.PHONY: clean-vect clean .PHONY: clean-vect clean
all: csdr ddcd 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 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 Auto-detected optimization parameters: $(PARAMS_SIMD)
@echo @echo
@ -54,8 +54,8 @@ libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c
-./parsevect dumpvect*.vect -./parsevect dumpvect*.vect
csdr: csdr.c libcsdr.so csdr: csdr.c libcsdr.so
gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) csdr.c $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o csdr gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) csdr.c $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o csdr
ddcd: ddcd.c libcsdr.so ddcd: ddcd.cpp libcsdr.so ddcd.h
gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) ddcd.c $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o ddcd g++ $(PARAMS_LOOPVECT) $(PARAMS_SIMD) ddcd.cpp $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o ddcd
arm-cross: clean-vect arm-cross: clean-vect
#note: this doesn't work since having added FFTW #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 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

View file

@ -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. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "ddcd.h"
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <getopt.h> #include <getopt.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <iostream>
#include <vector>
#include <unistd.h>
#define SOFTWARE_NAME "ddcd" #define SOFTWARE_NAME "ddcd"
#define MSG_START SOFTWARE_NAME ": " #define MSG_START SOFTWARE_NAME ": "
struct client_s typedef struct client_s
{ {
struct sockaddr_in addr;
int socket; int socket;
int addr; pid_t pid;
int pipefd[2];
} client_t; } client_t;
int host_port = 0; int host_port = 0;
@ -51,9 +60,6 @@ int main(int argc, char* argv[])
{ {
int c; int c;
//arguments:
for(;;) for(;;)
{ {
int option_index = 0; 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(!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); } 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; int listen_socket;
std::vector<client_t> clients; std::vector<client_t*> clients(10);
listen_socket=socket(AF_INET,SOCK_STREAM,0); listen_socket=socket(AF_INET,SOCK_STREAM,0);
memset(&addr_host,'0',sizeof(addr_host)); memset(&addr_host,'0',sizeof(addr_host));
addr_host.sin_family=AF_INET; addr_host.sin_family=AF_INET;
addr_host.sin_port=htons(8888); addr_host.sin_port=htons(host_port);
addr_host.sin_addr.s_addr=inet_addr("127.0.0.1");
*/ 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);
} }

1
ddcd.h Normal file
View file

@ -0,0 +1 @@
void client();