check_tcpclient now works (sort of...)

git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@541 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
This commit is contained in:
sears 2010-02-02 22:50:09 +00:00
parent 094a0d41ee
commit 3cbcb1e274
3 changed files with 32 additions and 11 deletions

View file

@ -440,6 +440,11 @@ void * thread_work_fn( void * args)
//step 1: read the opcode //step 1: read the opcode
uint8_t opcode; uint8_t opcode;
ssize_t n = read(*(item->data->workitem), &opcode, sizeof(uint8_t)); 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( n == sizeof(uint8_t));
assert( opcode < logserver::OP_INVALID ); assert( opcode < logserver::OP_INVALID );

View file

@ -16,11 +16,15 @@
#undef begin #undef begin
#undef end #undef end
static char * svrname = "localhost";
static int svrport = 32432;
void insertProbeIter(size_t NUM_ENTRIES) void insertProbeIter(size_t NUM_ENTRIES)
{ {
srand(1000); srand(1000);
std::string servername = "sherpa4"; std::string servername = svrname; //"sherpa4";
int serverport = 32432; int serverport = svrport; //32432;
double delete_freq = .05; double delete_freq = .05;
double update_freq = .15; double update_freq = .15;
@ -140,7 +144,8 @@ void insertProbeIter(size_t NUM_ENTRIES)
gettimeofday(&ti_st,0); gettimeofday(&ti_st,0);
//send the data //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); gettimeofday(&ti_end,0);
insert_time += tv_to_double(ti_end) - tv_to_double(ti_st); insert_time += tv_to_double(ti_end) - tv_to_double(ti_st);
@ -217,8 +222,14 @@ void insertProbeIter(size_t NUM_ENTRIES)
/** @test /** @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(25000);
insertProbeIter(100000); insertProbeIter(100000);
/* /*

View file

@ -162,13 +162,14 @@ datatuple * sendTuple(std::string & servername, int serverport, uint8_t opcode,
if (sockfd < 0) if (sockfd < 0)
{ {
printf("ERROR opening socket.\n"); perror("ERROR opening socket.\n");
return 0; return 0;
} }
server = gethostbyname(servername.c_str()); server = gethostbyname(servername.c_str());
if (server == NULL) { if (server == NULL) {
fprintf(stderr,"ERROR, no such host as %s\n", servername.c_str()); fprintf(stderr,"ERROR, no such host as %s\n", servername.c_str());
close(sockfd);
exit(0); exit(0);
} }
@ -182,7 +183,8 @@ datatuple * sendTuple(std::string & servername, int serverport, uint8_t opcode,
/* connect: create a connection with the server */ /* connect: create a connection with the server */
if (connect(sockfd, (sockaddr*) &serveraddr, sizeof(serveraddr)) < 0) if (connect(sockfd, (sockaddr*) &serveraddr, sizeof(serveraddr)) < 0)
{ {
printf("ERROR connecting\n"); perror("ERROR connecting\n");
close(sockfd);
return 0; return 0;
} }
@ -206,6 +208,8 @@ datatuple * sendTuple(std::string & servername, int serverport, uint8_t opcode,
uint8_t rcode; uint8_t rcode;
n = read(sockfd, (byte*) &rcode, sizeof(uint8_t)); n = read(sockfd, (byte*) &rcode, sizeof(uint8_t));
datatuple * ret;
if(rcode == logserver::OP_SENDING_TUPLE) if(rcode == logserver::OP_SENDING_TUPLE)
{ {
datatuple *rcvdtuple = (datatuple*)malloc(sizeof(datatuple)); 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); logserver::readfromsocket(sockfd, (byte*) rcvdtuple->data, *rcvdtuple->datalen);
} }
close(sockfd); ret = rcvdtuple;
return rcvdtuple; } else if(rcode == logserver::OP_SUCCESS) {
ret = &tuple;
} else {
ret = 0;
} }
else
assert(rcode == logserver::OP_SUCCESS);
close(sockfd); close(sockfd);
return 0; return ret;
} }