int oop_rd_read(oop_read *rd, const oop_rd_style *style, size_t maxrecsz, oop_rd_call *ifok, void *data_ok, oop_rd_call *iferr, void *data_err) { oop_source *oop= rd->oop; int er; cancel_time(oop,rd); cancel_read(oop,rd); if (style->delim_mode == OOP_RD_DELIM_NONE || rd->style.delim_mode == OOP_RD_DELIM_NONE || style->delim != rd->style.delim) rd->neednotcheck= 0; rd->style= *style; rd->maxrecsz= maxrecsz; rd->call_ok= ifok; rd->data_ok= data_ok; rd->call_err= iferr; rd->data_err= data_err; er= set_read(oop,rd); if (er) return er; er= set_time_ifbuf(oop,rd); if (er) return er; return 0; }
static void user_server(EXTENDED_CLIENT_SLOT *client) { int buflen; int fclient = client->socket; char buf[128]; char *oob; /* receive_oob(fclient); */ while( (buflen = read(fclient, buf, sizeof buf)) > 0 ) { /* get next command, after succefull login */ buf[buflen > 0 ? buflen : 0] = '\0'; fprintf(stderr, "Server: command \"%s\" received\n", buf); /* execute command */ if( strncmp(buf, "EXEC", 4 ) == 0 || strncmp(buf, "FORK", 4) == 0 ) { /* int client_no = get_client_count(); */ client->command = buf; client->user_function(client); reset_timeout_counter(); /* reset TIMEOUT counter */ continue; } else if(strncmp(buf, "CKPT", 4) == 0) /* set checkpoint flag */ { if(get_active_channels() > 0) { send_ack_nack(fclient, NOT_OK); close(fclient); continue; } exit_flag = 1; send_ack_nack(fclient, IS_OK); close(fclient); reset_timeout_counter(); /* reset TIMEOUT counter */ exit_from_client_thread(client); } else if(strncmp(buf, "NOOP", 4) == 0) /* null operation, reset client counter */ { send_ack_nack(fclient, IS_OK); close(fclient); reset_timeout_counter(); /* reset TIMEOUT counter */ exit_from_client_thread(client); } else if(strncmp(buf, "STATUS", 6) == 0) /* get active channels */ { fprintf(stderr, "STATUS Command\n"); send_ack_nack(fclient, IS_OK); get_status_all(fclient); close(fclient); reset_timeout_counter(); /* reset TIMEOUT counter */ exit_from_client_thread(client); } else if(strncmp(buf, "ABORT", 5) == 0) /* emergency, kill server */ { fprintf(stderr, "Server process will be stopped !!!\n"); send_ack_nack(fclient, IS_OK); close(fclient); kill(ping_pid, 9); exit(1); } /********* out-of-band data exchange */ else if(strncmp(buf, "WRITE_OOB", 9) == 0) /* write oob message */ { /* write to buffer */ int nbytes = 0; send_ack_nack(fclient, IS_OK); oob = (char *)malloc(6); nbytes = read(fclient, oob, 6); oob += nbytes; *oob = '\0'; oob -= nbytes; if(oob) fprintf(stderr, "WRITE_OOB Command, message \"%s\" length = %d \n", oob, nbytes); fprintf(stderr, "WRITE_OOB Command, strcmp(oob, \"ABCDEF\") = %d \n", strcmp(oob, "ABCDEF")); close(fclient); } else if(strncmp(buf, "READ_OOB", 8) == 0) /* read oob message */ { /* read from buffer*/ send_ack_nack(fclient, IS_OK); oob = (char *)malloc(10); oob = "GHIJKL"; if(oob && strlen(oob) > 0) { if(write(fclient, oob, strlen(oob)) <= 0) { fprintf(stderr, "READ_OOB: Can't write oob\n"); } fprintf(stderr, "READ_OOB: send oob = %s\n", oob); } else fprintf(stderr, "READ_OOB Command, oob null \n"); close(fclient); } /********** out-of-band data exchange */ else if( strncmp( buf, "END", 3 ) == 0 ) { char *channel; /* int client_no; */ channel = (char *)malloc( 1024 ); send_ack_nack( fclient, IS_OK ); /* send ACK to indicate that command is accepted */ /* client_no = get_client_count(); */ sscanf( buf, "END %s", channel ); cancel_read( channel ); reset_timeout_counter(); /* reset TIMEOUT counter */ close( fclient ); if( channel ) free( channel ); } else { /* assumed to be a bum call */ printf("Bad Command: \"%s\"\n", buf); send_ack_nack(fclient, NOT_OK); /* send NACK to indicate that command is rejected */ reset_timeout_counter(); /* reset TIMEOUT counter */ continue; /* connection terminated, next client please */ } } }
void oop_rd_cancel(oop_read *rd) { cancel_time(rd->oop,rd); cancel_read(rd->oop,rd); }