From 5064d3b72c79bdaeb5d5ce06c09b3d0b563d010f Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Tue, 7 Jun 2016 22:14:36 +0200 Subject: [PATCH] Added a lot of things, tsmpool should now work in 1R1W mode as well --- ddcd.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- ddcd.h | 13 +++++++++++++ tsmpool.cpp | 7 ++++--- tsmpool.h | 1 + 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/ddcd.cpp b/ddcd.cpp index e16a5c2..9a76d56 100644 --- a/ddcd.cpp +++ b/ddcd.cpp @@ -173,6 +173,7 @@ int main(int argc, char* argv[]) //Create tsmpool tsmpool* pool = new tsmpool(bufsize, bufcnt); + if(!pool->ok) print_exit(MSG_START "tsmpool failed to initialize\n"); unsigned char* current_write_buffer = pool->get_write_buffer(); int index_in_current_write_buffer = 0; @@ -198,13 +199,13 @@ int main(int argc, char* argv[]) clients.push_back(new_client); fprintf(stderr, MSG_START "pthread_create() done, clients now: %d\n", clients.size()); } - else fprintf(stderr, MSG_START "pthread_create() failed."); + else fprintf(stderr, MSG_START "pthread_create() failed.\n"); } if(index_in_current_write_buffer >= bufsize) { current_write_buffer = pool->get_write_buffer(); - index_in_current_write_buffer = 0; + index_in_current_write_buffer = 0;error_exiterror_exit } int retval = read(input_fd, current_write_buffer + index_in_current_write_buffer, bufsize - index_in_current_write_buffer); if(retval>0) @@ -263,18 +264,54 @@ void clients_close_all_finished() } } +void client_parser_push(char c) +{ //!TODO + command_t cmd; + char* commands_cstr = commands.c_str(); + int newline_index = -1; + + for(int i=0;commands_cstr[i];i++) if(commands_cstr[i]=='\n') newline_index = i; + if(newline_index == -1) + + char param_name[101]; + char param_value[101]; + for(int i=0;i<100;commands_csdr + +} + void* client_thread (void* param) //!TODO { client_t* me_the_client = (client_t*)param; + me_the_client->status = CS_THREAD_RUNNING; + char ctl_data_buffer; + int retval; + for(;;) + { + do + { + retval = recv(me_the_client->socket, &ctl_data_buffer, 1, 0); + if(client_parser_push(ctl_data_buffer)) break; + } while (retval); + //read control data from socket + //process control data + //run shift + //run decimation + //have an exit condition (??) + if(ddc_method == M_TD) + { + + } + } + me_the_client->status = CS_THREAD_FINISHED; pthread_exit(NULL); return NULL; } void error_exit(const char* why) { - perror(why); + perror(why); //do we need a \n at the end of (why)? exit(1); } diff --git a/ddcd.h b/ddcd.h index 37cb658..766be47 100644 --- a/ddcd.h +++ b/ddcd.h @@ -38,6 +38,19 @@ typedef struct client_s } client_t; +typedef enum command_type_e +{ + CT_SHIFT, + CT_BYPASS +} command_type_t; + + +typedef struct command_s +{ + command_type_t type; + float float_param; +} command_t; + void print_exit(const char* why); void error_exit(const char* why); void maxfd(int* maxfd, int fd); diff --git a/tsmpool.cpp b/tsmpool.cpp index 6593595..67507c5 100644 --- a/tsmpool.cpp +++ b/tsmpool.cpp @@ -46,9 +46,10 @@ int tsmpool::remove_thread(tsmthread_t* thread) void* tsmpool::get_read_buffer(tsmthread_t* thread) { - if(thread->read_index==index_before(write_index)) return NULL; - void* to_return = buffers[thread->read_index]; - thread->read_index=index_next(thread->read_index); + int* actual_read_index = (thread==NULL) ? &my_read_index : &thread->read_index; + if(*actual_read_index==index_before(write_index)) return NULL; + void* to_return = buffers[*actual_read_index]; + *actual_read_index=index_next(*actual_read_index); } void* tsmpool::set_read_index_distance(tsmthread_t* thread, int distance) diff --git a/tsmpool.h b/tsmpool.h index 2f097d1..f4901cc 100644 --- a/tsmpool.h +++ b/tsmpool.h @@ -20,6 +20,7 @@ private: int ok; int write_index; //it always points to the next buffer to be written int lowest_read_index; //unused + int my_read_index; //it is used when tsmpool is used as a single writer - single reader circular buffer public: size_t get_size();