diff --git a/logserver.cpp b/logserver.cpp index bb0b1fe..8d26cb6 100644 --- a/logserver.cpp +++ b/logserver.cpp @@ -440,6 +440,11 @@ void * thread_work_fn( void * args) //step 1: read the opcode uint8_t opcode; ssize_t n = read(*(item->data->workitem), &opcode, sizeof(uint8_t)); + if(n == 0) { + opcode = logserver::OP_DONE; + n = sizeof(uint8_t); + printf("Obsolescent client closed connection uncleanly\n"); + } assert( n == sizeof(uint8_t)); assert( opcode < logserver::OP_INVALID ); diff --git a/test/check_tcpclient.cpp b/test/check_tcpclient.cpp index a5c637b..ae05455 100644 --- a/test/check_tcpclient.cpp +++ b/test/check_tcpclient.cpp @@ -16,11 +16,15 @@ #undef begin #undef end + +static char * svrname = "localhost"; +static int svrport = 32432; + void insertProbeIter(size_t NUM_ENTRIES) { srand(1000); - std::string servername = "sherpa4"; - int serverport = 32432; + std::string servername = svrname; //"sherpa4"; + int serverport = svrport; //32432; double delete_freq = .05; double update_freq = .15; @@ -140,7 +144,8 @@ void insertProbeIter(size_t NUM_ENTRIES) gettimeofday(&ti_st,0); //send the data - sendTuple(servername, serverport, logserver::OP_INSERT, newtuple); + datatuple * ret = sendTuple(servername, serverport, logserver::OP_INSERT, newtuple); + assert(ret); gettimeofday(&ti_end,0); insert_time += tv_to_double(ti_end) - tv_to_double(ti_st); @@ -217,8 +222,14 @@ void insertProbeIter(size_t NUM_ENTRIES) /** @test */ -int main() +int main(int argc, char* argv[]) { + if(argc > 1) { + svrname = argv[1]; + } + if(argc > 2) { + svrport = atoi(argv[2]); + } //insertProbeIter(25000); insertProbeIter(100000); /* diff --git a/test/check_util.h b/test/check_util.h index 46d4414..47ee15b 100644 --- a/test/check_util.h +++ b/test/check_util.h @@ -162,13 +162,14 @@ datatuple * sendTuple(std::string & servername, int serverport, uint8_t opcode, if (sockfd < 0) { - printf("ERROR opening socket.\n"); + perror("ERROR opening socket.\n"); return 0; } server = gethostbyname(servername.c_str()); if (server == NULL) { fprintf(stderr,"ERROR, no such host as %s\n", servername.c_str()); + close(sockfd); exit(0); } @@ -182,7 +183,8 @@ datatuple * sendTuple(std::string & servername, int serverport, uint8_t opcode, /* connect: create a connection with the server */ if (connect(sockfd, (sockaddr*) &serveraddr, sizeof(serveraddr)) < 0) { - printf("ERROR connecting\n"); + perror("ERROR connecting\n"); + close(sockfd); return 0; } @@ -206,6 +208,8 @@ datatuple * sendTuple(std::string & servername, int serverport, uint8_t opcode, uint8_t rcode; n = read(sockfd, (byte*) &rcode, sizeof(uint8_t)); + datatuple * ret; + if(rcode == logserver::OP_SENDING_TUPLE) { datatuple *rcvdtuple = (datatuple*)malloc(sizeof(datatuple)); @@ -227,14 +231,15 @@ datatuple * sendTuple(std::string & servername, int serverport, uint8_t opcode, logserver::readfromsocket(sockfd, (byte*) rcvdtuple->data, *rcvdtuple->datalen); } - close(sockfd); - return rcvdtuple; + ret = rcvdtuple; + } else if(rcode == logserver::OP_SUCCESS) { + ret = &tuple; + } else { + ret = 0; } - else - assert(rcode == logserver::OP_SUCCESS); close(sockfd); - return 0; + return ret; }