Go to the source code of this file.
|
|
Definition at line 58 of file rototalk.h. 00058 {
00059 rototalk_success = 0,
00060 rototalk_err_whoami,
00061 rototalk_err_alreadyconn,
00062 rototalk_err_unknownhost,
00063 rototalk_err_notinethost,
00064 rototalk_err_socketfail,
00065 rototalk_err_connectfail,
00066 rototalk_err_notconnected,
00067 rototalk_err_illegalmethod,
00068 rototalk_err_badsender,
00069 rototalk_err_badsendcmd,
00070 rototalk_err_badsendsize,
00071 rototalk_err_badsenddata,
00072 rototalk_err_badrecvack,
00073 rototalk_err_badrecvacksize,
00074 rototalk_err_badrecvackdata,
00075 rototalk_err_badrecvstate,
00076 rototalk_err_nack,
00077 rototalk_err_reallocate,
00078 rototalk_err_badconfig,
00079 rototalk_last_of_errors
00080 };
|
|
|
Definition at line 836 of file rototalk.c. References g_roto_beammonfile, MINOS_ROOTER_BEAMMON, roto_beammonfile::nsec, roto_closef, roto_set_std_file_status(), and roto_beammonfile::sec. Referenced by BeamData::close_file(), RotoClient::CloseBeamMonFile(), roto_open_beammonfile(), and send_bogus_stuff(). 00837 {
00838 int err;
00839 err = roto_set_std_file_status(roto_closef,MINOS_ROOTER_BEAMMON,0,
00840 g_roto_beammonfile.sec,
00841 g_roto_beammonfile.nsec);
00842
00843 if (!err) {
00844 g_roto_beammonfile.sec = 0;
00845 g_roto_beammonfile.nsec = 0;
00846 }
00847 return err;
00848 }
|
|
|
Definition at line 401 of file rototalk.c. References roto_conn::conn_host, roto_conn::conn_nrec_sent, roto_conn::conn_port, roto_conn::conn_socketfd, g_roto_conn, iam, logError(), logInfo(), roto_complete_cmd(), roto_disconn, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. Referenced by BeamData::close_connection(), RotoClient::CloseConnection(), and main(). 00402 {
00403 rotocmd cmd;
00404 int err;
00405
00406 /*
00407 * complain if we aren't actually connected
00408 */
00409 if (g_roto_conn.conn_socketfd<0) {
00410 logError("roto_close_connection: not connected");
00411 return rototalk_err_notconnected;
00412 }
00413
00414 /*
00415 * Send "command" in fashion similar to run control protocol
00416 */
00417 cmd = roto_complete_cmd(roto_disconn,iam);
00418 err = roto_send_command(cmd,0,0);
00419 if (err) return err;
00420 /*
00421 * Get the command reply (ACK|NACK + state report)
00422 */
00423 err = roto_recv_cmdreply(cmd);
00424
00425 /* vicious (cf. man -S 2 shutdown) without regard to further send/receives
00426 shutdown(conn_socket,2)
00427 */
00428
00429 /*
00430 * friendly closing of the socket
00431 */
00432 errno = 0;
00433 while ( close(g_roto_conn.conn_socketfd) == -1 &&
00434 errno == EINTR ) errno = 0;
00435
00436 /*
00437 * make a note that we're not connected
00438 */
00439 g_roto_conn.conn_socketfd = -1;
00440 strcpy(g_roto_conn.conn_host,"no-longer-connected");
00441 g_roto_conn.conn_port = 0;
00442 g_roto_conn.conn_nrec_sent = 0;
00443
00444 if (roto_verbose>0)
00445 logInfo("roto_close_connection requested");
00446
00447 return err;
00448 }
|
|
||||||||||||||||
|
Definition at line 674 of file rototalk.c. References MINOS_ROOTER_DCP, roto_closef, roto_set_std_file_status(), and run(). Referenced by RotoClient::CloseDAQFile(). 00675 {
00676 return roto_set_std_file_status(roto_closef,MINOS_ROOTER_DCP,
00677 detector,run,subrun);
00678 }
|
|
|
Definition at line 751 of file rototalk.c. References roto_dcsfile::detector, g_roto_dcsfile, MINOS_ROOTER_DCS, roto_dcsfile::nsec, roto_closef, roto_set_std_file_status(), and roto_dcsfile::sec. Referenced by RotoClient::CloseDCSFile(), and roto_open_dcsfile(). 00752 {
00753 int err;
00754 err = roto_set_std_file_status(roto_closef,MINOS_ROOTER_DCS,
00755 g_roto_dcsfile.detector,
00756 g_roto_dcsfile.sec,
00757 g_roto_dcsfile.nsec);
00758
00759 if (!err) {
00760 g_roto_dcsfile.detector = 0;
00761 g_roto_dcsfile.sec = 0;
00762 g_roto_dcsfile.nsec = 0;
00763 }
00764 return err;
00765 }
|
|
|
Definition at line 883 of file rototalk.c. References roto_closef, and roto_set_named_file_status(). Referenced by RotoClient::CloseFile(), and send_whole_file(). 00884 {
00885 return roto_set_named_file_status(roto_closef,fname);
00886 }
|
|
|
Definition at line 203 of file rototalk.c. References MINOS_ROOTER_BEAMMON, ROOTER_PORT_BEAMMON, and roto_open_connection(). Referenced by main(), and BeamData::open_connection(). 00204 {
00205 return roto_open_connection(host,ROOTER_PORT_BEAMMON,MINOS_ROOTER_BEAMMON);
00206 }
|
|
||||||||||||
|
Definition at line 785 of file rototalk.c. References g_roto_beammonfile, logError(), MINOS_ROOTER_BEAMMON, roto_beammonfile::nsec, roto_close_beammonfile(), roto_openf, roto_set_std_file_status(), and roto_beammonfile::sec. Referenced by BeamData::open_file(), RotoClient::OpenBeamMonFile(), and send_bogus_stuff(). 00786 {
00787 int err;
00788
00789 if (g_roto_beammonfile.sec != 0 ||
00790 g_roto_beammonfile.nsec != 0 ) {
00791 /* a file is already open */
00792
00793 if (g_roto_beammonfile.sec == sec ||
00794 g_roto_beammonfile.nsec == nsec ) {
00795 /* do nothing, requested the same file ... */
00796 return rototalk_success;
00797 }
00798
00799 /* a different file is already open! */
00800 logError("roto_open_beammonfile:");
00801 logError(" a file (0x%8.8x 0x%8.8x) is already open",
00802 g_roto_beammonfile.sec,g_roto_beammonfile.nsec);
00803 logError(" close it and open (0x%8.8x 0x%8.8x)",
00804 sec,nsec);
00805 roto_close_beammonfile();
00806 }
00807
00808
00809 err = roto_set_std_file_status(roto_openf,MINOS_ROOTER_BEAMMON,
00810 0,sec,nsec);
00811 if (!err) {
00812 g_roto_beammonfile.sec = sec;
00813 g_roto_beammonfile.nsec = nsec;
00814 }
00815
00816 return err;
00817 }
|
|
||||||||||||||||
|
Definition at line 224 of file rototalk.c. References roto_conn::conn_host, roto_conn::conn_nrec_sent, roto_conn::conn_port, roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), logInfo(), logWarn(), MINOS_ROOTER_BEAMMON, MINOS_ROOTER_DCP, MINOS_ROOTER_DCS, port, roto_complete_cmd(), roto_connect, roto_recv_cmdreply(), roto_send_command(), roto_set_connection_nodelay(), roto_verbose, and rotocmd. Referenced by main(), roto_open_BeamMon_connection(), roto_open_DCP_connection(), roto_open_DCS_connection(), and RotoClient::SetupConnection(). 00225 {
00226 const char *whoami_name = "unknown";
00227 int socketfd = 0;
00228 struct hostent *host_ptr;
00229 struct sockaddr_in serv_addr;
00230 unsigned long int addr; /* good for 4 byte address */
00231 struct in_addr ad;
00232
00233 int err;
00234 rotocmd cmd;
00235
00236 switch (whoami) {
00237 case MINOS_ROOTER_DCP: whoami_name = "DCP"; break;
00238 case MINOS_ROOTER_DCS: whoami_name = "DCS"; break;
00239 case MINOS_ROOTER_BEAMMON: whoami_name = "BeamMon"; break;
00240 default:
00241 logError("roto_open_connection: whoami 0x%02x is not allowed",whoami);
00242 return rototalk_err_whoami;
00243 }
00244 iam = whoami;
00245
00246 if (g_roto_conn.conn_socketfd>0) {
00247 logError("roto_open_connection: already established to %s:%d",
00248 g_roto_conn.conn_host,g_roto_conn.conn_port);
00249
00250 /*
00251 * should we close that connection and reopen
00252 * or simply return a failure??
00253 * ... for now simply leave existing one open
00254 */
00255 return rototalk_err_alreadyconn;
00256 }
00257
00258 /*
00259 * code based on both:
00260 * Unix Network Programming, W. Richard Stevens, Prentice Hall, pg 286
00261 * ROOT TSocket and TUnixSystem classes
00262 */
00263
00264 /*
00265 * prepare the address structure
00266 */
00267
00268 memset(&serv_addr,0,sizeof(serv_addr)); /* clear the structure */
00269 #ifdef HASNOT_INETATON
00270 logWarn("roto_open_connection: using obsolete inet_addr() function");
00271
00272 if ((addr = (unsigned long int)inet_addr(host))
00273 != INADDR_NONE) {
00274 #else
00275 if (inet_aton(host, &ad)) {
00276 memcpy(&addr, &ad.s_addr, sizeof(ad.s_addr));
00277 #endif
00278 if (!(host_ptr = gethostbyaddr((const char *)&addr,
00279 sizeof(addr), AF_INET))) {
00280 /* unnamed host */
00281 }
00282 }
00283 else if ((host_ptr = gethostbyname(host))) {
00284 logDebug(3,"roto_open_connection: resorted to gethostbyname");
00285 }
00286 if (!host_ptr) {
00287 logError("roto_open_connection: unknown host %s",host);
00288 return rototalk_err_unknownhost;
00289 }
00290 if (host_ptr->h_addrtype != AF_INET) {
00291 logError("roto_open_connection: %s not an internet host",host);
00292 return rototalk_err_notinethost;
00293 }
00294
00295 /*
00296 * Magic incantation
00297 */
00298 memcpy(&addr,host_ptr->h_addr,host_ptr->h_length);
00299 serv_addr.sin_family = AF_INET;
00300 serv_addr.sin_addr.s_addr = addr;
00301 serv_addr.sin_port = htons(port);
00302
00303 /*
00304 * Open the TCP socket (an Internet stream socket)
00305 */
00306 if ( (socketfd = socket(AF_INET,SOCK_STREAM, 0)) < 0 ) {
00307 logError("roto_open_connection: failed to open socket");
00308 return rototalk_err_socketfail;
00309 }
00310
00311 /*
00312 * Connect to the server
00313 */
00314 if (connect(socketfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) {
00315 logError("roto_open_connection: can't connect");
00316 logError(" host '%s' expanded '%s' port %d",host,host_ptr->h_name,port);
00317 logError(" sin_addr.s_addr 0x%8.8x sin_port 0x%4.4x",
00318 serv_addr.sin_addr.s_addr,serv_addr.sin_port);
00319 return rototalk_err_connectfail;
00320 }
00321
00322 /*
00323 * Save a copy of who we're connected to
00324 */
00325 g_roto_conn.conn_socketfd = socketfd;
00326 strcpy(g_roto_conn.conn_host,host_ptr->h_name); /* copy the expanded name */
00327 g_roto_conn.conn_port = port;
00328 g_roto_conn.conn_nrec_sent = 0;
00329
00330 /*
00331 * by default make connection use TCP_NODELAY
00332 */
00333 roto_set_connection_nodelay(1);
00334
00335 if (roto_verbose>0) {
00336 logInfo("roto_open_connection: %s:%d, i am '%s'",
00337 host,port,whoami_name);
00338 }
00339
00340 /*
00341 * Send "command" in fashion similar to run control protocol
00342 */
00343 cmd = roto_complete_cmd(roto_connect,iam);
00344 err = roto_send_command(cmd,0,0);
00345 if (err) return err;
00346 /*
00347 * Get the command reply (ACK|NACK + state report)
00348 */
00349 return roto_recv_cmdreply(cmd);
00350 }
|
|
||||||||||||||||
|
Definition at line 653 of file rototalk.c. References MINOS_ROOTER_DCP, roto_openf, roto_set_std_file_status(), and run(). Referenced by RotoClient::OpenDAQFile(). 00654 {
00655 return roto_set_std_file_status(roto_openf,MINOS_ROOTER_DCP,
00656 detector,run,subrun);
00657 }
|
|
|
Definition at line 195 of file rototalk.c. References MINOS_ROOTER_DCP, ROOTER_PORT_DAQ, and roto_open_connection(). Referenced by main(). 00196 {
00197 return roto_open_connection(host,ROOTER_PORT_DAQ,MINOS_ROOTER_DCP);
00198 }
|
|
|
Definition at line 199 of file rototalk.c. References MINOS_ROOTER_DCS, ROOTER_PORT_DCS, and roto_open_connection(). Referenced by main(). 00200 {
00201 return roto_open_connection(host,ROOTER_PORT_DCS,MINOS_ROOTER_DCS);
00202 }
|
|
||||||||||||||||
|
Definition at line 698 of file rototalk.c. References roto_dcsfile::detector, g_roto_dcsfile, logError(), MINOS_ROOTER_DCS, roto_dcsfile::nsec, roto_close_dcsfile(), roto_openf, roto_set_std_file_status(), and roto_dcsfile::sec. Referenced by RotoClient::OpenDCSFile(). 00699 {
00700 int err;
00701
00702 if (g_roto_dcsfile.detector != 0 ||
00703 g_roto_dcsfile.sec != 0 ||
00704 g_roto_dcsfile.nsec != 0 ) {
00705 /* a file is already open */
00706
00707 if (g_roto_dcsfile.detector == detector ||
00708 g_roto_dcsfile.sec == sec ||
00709 g_roto_dcsfile.nsec == nsec ) {
00710 /* do nothing, requested the same file ... */
00711 return rototalk_success;
00712 }
00713
00714 /* a different file is already open! */
00715 logError("roto_open_dcsfile:");
00716 logError(" a file (0x%2.2x 0x%8.8x 0x%8.8x) is already open",
00717 g_roto_dcsfile.detector,g_roto_dcsfile.sec,g_roto_dcsfile.nsec);
00718 logError(" close it and open (0x%2.2x 0x%8.8x 0x%8.8x)",
00719 detector,sec,nsec);
00720 roto_close_dcsfile();
00721 }
00722
00723 err = roto_set_std_file_status(roto_openf,MINOS_ROOTER_DCS,
00724 detector,sec,nsec);
00725 if (!err) {
00726 g_roto_dcsfile.detector = detector;
00727 g_roto_dcsfile.sec = sec;
00728 g_roto_dcsfile.nsec = nsec;
00729 }
00730
00731 return err;
00732 }
|
|
|
Definition at line 864 of file rototalk.c. References roto_openf, and roto_set_named_file_status(). Referenced by RotoClient::OpenFile(), and send_whole_file(). 00865 {
00866 return roto_set_named_file_status(roto_openf,fname);
00867 }
|
|
|
Definition at line 1219 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logError(), logNotice(), roto_complete_cmd(), roto_recv_cmdreply(), roto_send_command(), roto_shutdown, roto_verbose, and rotocmd. Referenced by main(), and RotoClient::SendShutdownMessage(). 01220 {
01221 rotocmd cmd;
01222 int err;
01223
01224 if (g_roto_conn.conn_socketfd<0) {
01225 logError("roto_request_shutdown: not connected");
01226 return rototalk_err_notconnected;
01227 }
01228
01229 /*
01230 * Send "command" in fashion similar to run control protocol
01231 */
01232 cmd = roto_complete_cmd(roto_shutdown,iam);
01233 err = roto_send_command(cmd,&priority,sizeof(int));
01234 if (err) return err;
01235
01236 if (roto_verbose>0)
01237 logNotice("roto_request_shutdown (priority=%d)",priority);
01238
01239 /*
01240 * Get the command reply (ACK|NACK + state report)
01241 */
01242 return roto_recv_cmdreply(cmd);
01243
01244 }
|
|
||||||||||||||||
|
Definition at line 510 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), roto_complete_cmd(), roto_config, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. 00511 {
00512 rotocmd cmd;
00513 int err;
00514 char minibuffer[4096];
00515
00516 if (g_roto_conn.conn_socketfd<0) {
00517 logError("roto_send_autosave_config: not connected");
00518 return rototalk_err_notconnected;
00519 }
00520
00521 if (roto_verbose>1)
00522 logDebug(2,"roto_send_autosave_config: stream \"%s\" - %d rec, %d sec",
00523 stream,nrec,nsec);
00524
00525 /* format the config */
00526 sprintf(minibuffer,"config autosave: %s = %d rec %d sec",stream,nrec,nsec);
00527
00528 /*
00529 * Send "command" in fashion similar to run control protocol
00530 */
00531 cmd = roto_complete_cmd(roto_config,iam);
00532 err = roto_send_command(cmd,minibuffer,strlen(minibuffer));
00533 if (err) return err;
00534 /*
00535 * Get the command reply (ACK|NACK + state report)
00536 */
00537 return roto_recv_cmdreply(cmd);
00538 }
|
|
||||||||||||
|
Definition at line 604 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), roto_complete_cmd(), roto_config, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. 00605 {
00606 rotocmd cmd;
00607 int err;
00608 char minibuffer[4096];
00609
00610 if (g_roto_conn.conn_socketfd<0) {
00611 logError("roto_send_basketsize_config: not connected");
00612 return rototalk_err_notconnected;
00613 }
00614
00615 if (roto_verbose>1)
00616 logDebug(2,"roto_send_basketsize_config: stream \"%s\" - basketsize %d",
00617 stream,bsize);
00618
00619 /* format the config */
00620 sprintf(minibuffer,"config basketsize: %s = %d ",stream,bsize);
00621
00622 /*
00623 * Send "command" in fashion similar to run control protocol
00624 */
00625 cmd = roto_complete_cmd(roto_config,iam);
00626 err = roto_send_command(cmd,minibuffer,strlen(minibuffer));
00627 if (err) return err;
00628 /*
00629 * Get the command reply (ACK|NACK + state report)
00630 */
00631 return roto_recv_cmdreply(cmd);
00632 }
|
|
||||||||||||
|
Definition at line 559 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), roto_complete_cmd(), roto_config, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. 00560 {
00561 rotocmd cmd;
00562 int err;
00563 char minibuffer[4096];
00564
00565 if (g_roto_conn.conn_socketfd<0) {
00566 logError("roto_send_compress_config: not connected");
00567 return rototalk_err_notconnected;
00568 }
00569
00570 if (roto_verbose>1)
00571 logDebug(2,"roto_send_compress_config: stream \"%s\" - compress %d",
00572 stream,level);
00573
00574 /* format the config */
00575 sprintf(minibuffer,"config compress: %s = %d ",stream,level);
00576
00577 /*
00578 * Send "command" in fashion similar to run control protocol
00579 */
00580 cmd = roto_complete_cmd(roto_config,iam);
00581 err = roto_send_command(cmd,minibuffer,strlen(minibuffer));
00582 if (err) return err;
00583 /*
00584 * Get the command reply (ACK|NACK + state report)
00585 */
00586 return roto_recv_cmdreply(cmd);
00587 }
|
|
||||||||||||
|
Definition at line 465 of file rototalk.c. References roto_conn::conn_nrec_sent, roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), roto_complete_cmd(), roto_recbuff, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. Referenced by send_bogus_stuff(), BeamData::send_data(), send_whole_file(), and RotoClient::SendRecordBuffer(). 00466 {
00467 rotocmd cmd;
00468 int err;
00469
00470 if (g_roto_conn.conn_socketfd<0) {
00471 logError("roto_send_record: not connected");
00472 return rototalk_err_notconnected;
00473 }
00474
00475 g_roto_conn.conn_nrec_sent++;
00476
00477 if (roto_verbose>2)
00478 logDebug(3,"roto_send_record: record %d, %d bytes",
00479 g_roto_conn.conn_nrec_sent,nbytes);
00480
00481 /*
00482 * Send "command" in fashion similar to run control protocol
00483 */
00484 cmd = roto_complete_cmd(roto_recbuff,iam);
00485 err = roto_send_command(cmd,buffer,nbytes);
00486 if (err) return err;
00487 /*
00488 * Get the command reply (ACK|NACK + state report)
00489 */
00490 return roto_recv_cmdreply(cmd);
00491 }
|
|
|
Definition at line 366 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, logError(), logWarn(), and roto_verbose. Referenced by main(), and roto_open_connection(). 00367 {
00368 int err;
00369
00370 /*
00371 * complain if we aren't actually connected
00372 */
00373 if (g_roto_conn.conn_socketfd<0) {
00374 logError("roto_set_connection_nodelay: not connected");
00375 return rototalk_err_notconnected;
00376 }
00377
00378 err = setsockopt(g_roto_conn.conn_socketfd,IPPROTO_TCP,TCP_NODELAY,
00379 (char*)&val, sizeof(val));
00380
00381 if (roto_verbose>0 && err)
00382 logWarn("roto_set_connection_nodelay returned %d",err);
00383
00384 return err;
00385 }
|
|
|
Definition at line 44 of file rototalk.c. Referenced by main(), roto_close_connection(), roto_open_connection(), roto_request_shutdown(), roto_send_autosave_config(), roto_send_basketsize_config(), roto_send_compress_config(), roto_send_record(), roto_set_connection_nodelay(), roto_set_named_file_status(), and roto_set_std_file_status(). |
1.3.9.1