/****** sge_client_ijs/stop_ijs_server() *************************************** * NAME * stop_ijs_server() -- stops the commlib server for the builtin * interactive job support * * SYNOPSIS * int stop_ijs_server(COMM_HANDLE **phandle, dstring *p_err_msg) * * FUNCTION * Stops the commlib server for the commlib connection between the shepherd * of the interactive job (qrsh/qlogin) and the qrsh/qlogin command. * Over this connectin the stdin/stdout/stderr input/output is transferred. * * INPUTS * COMM_HANDLE **phandle - Pointer to the COMM server handle. Gets set to * NULL in this function. * dstring *p_err_msg - Contains the error reason in case of error. * * RESULT * int - 0: OK * 1: Invalid Parameter: phandle = NULL * 2: General error shutting down the COMM server, * see p_err_msg for details * * NOTES * MT-NOTE: stop_ijs_server() is not MT safe * * SEE ALSO * sge_client_ijs/start_ijs_server() * sge_client_ijs/run_ijs_server() * sge_client_ijs/force_ijs_server_shutdown() *******************************************************************************/ int stop_ijs_server(COMM_HANDLE **phandle, dstring *p_err_msg) { int ret = 0; DENTER(TOP_LAYER, "stop_ijs_server"); if (phandle == NULL) { ret = 1; } else if (*phandle != NULL) { cl_com_set_error_func(NULL); #if 0 cl_log_list_set_log_level(cl_com_get_log_list(), CL_LOG_OFF); #endif cl_com_ignore_timeouts(CL_TRUE); DPRINTF(("shut down the connection from our side\n")); ret = cl_commlib_shutdown_handle(*phandle, CL_FALSE); if (ret != CL_RETVAL_OK) { sge_dstring_sprintf(p_err_msg, "error shutting down the connection: %s", cl_get_error_text(ret)); ret = 2; } *phandle = NULL; } DRETURN(ret); }
/*---------------------------------------------------------------*/ void sighandler_client( int sig ) { /* thread_signal_receiver = pthread_self(); */ if (sig == SIGPIPE || sig == SIGHUP) { return; } /* shutdown all sockets */ do_shutdown = 1; cl_com_ignore_timeouts(CL_TRUE); }
extern int main(int argc, char** argv) { struct sigaction sa; cl_com_handle_t* handle = NULL; cl_com_message_t* message = NULL; cl_com_endpoint_t* sender = NULL; #if 0 cl_com_endpoint_t* clients[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; #endif int i; unsigned long max_connections; if (argc != 4) { printf("please enter debug level, port and nr. of max connections\n"); exit(1); } /* setup signalhandling */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = sighandler_server; /* one handler for all signals */ sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sigaction(SIGPIPE, &sa, NULL); printf("commlib setup ...\n"); cl_com_setup_commlib(CL_RW_THREAD, (cl_log_t)atoi(argv[1]), NULL); printf("setting up service on port %d\n", atoi(argv[2]) ); handle=cl_com_create_handle(NULL,CL_CT_TCP,CL_CM_CT_MESSAGE , CL_TRUE, atoi(argv[2]) , CL_TCP_DEFAULT,"server", 1, 2, 0 ); if (handle == NULL) { printf("could not get handle\n"); exit(-1); } cl_com_get_service_port(handle,&i), printf("server running on host \"%s\", port %d, component name is \"%s\", id is %ld\n", handle->local->comp_host, i, handle->local->comp_name, handle->local->comp_id); cl_com_set_max_connections(handle,atoi(argv[3])); cl_com_get_max_connections(handle,&max_connections); printf("max open connections is set to %lu\n", max_connections); printf("enable max connection close\n"); cl_com_set_max_connection_close_mode(handle, CL_ON_MAX_COUNT_CLOSE_AUTOCLOSE_CLIENTS); while(do_shutdown != 1) { unsigned long mid; int ret_val; struct timeval now; CL_LOG(CL_LOG_INFO,"main()"); gettimeofday(&now,NULL); cl_commlib_trigger(handle, 1); ret_val = cl_commlib_receive_message(handle,NULL, NULL, 0, CL_FALSE, 0, &message, &sender); if (message != NULL ) { ret_val = cl_commlib_send_message(handle, sender->comp_host, sender->comp_name, sender->comp_id, CL_MIH_MAT_NAK, &message->message, message->message_length, &mid, message->message_id,0, CL_FALSE, CL_FALSE); if (ret_val != CL_RETVAL_OK) { /* printf("cl_commlib_send_message() returned: %s\n",cl_get_error_text(ret_val)); */ } /* printf("received message from \"%s\": size of message: %ld\n", sender->comp_host, message->message_length); */ cl_com_free_message(&message); cl_com_free_endpoint(&sender); message = NULL; } } cl_com_ignore_timeouts(CL_TRUE); cl_com_get_ignore_timeouts_flag(); printf("shutting down server ...\n"); handle = cl_com_get_handle( "server", 1 ); if (handle == NULL) { printf("could not find handle\n"); exit(1); } else { printf("found handle\n"); } while ( cl_commlib_shutdown_handle(handle, CL_TRUE) == CL_RETVAL_MESSAGE_IN_BUFFER) { message = NULL; cl_commlib_receive_message(handle, NULL, NULL, 0, CL_FALSE, 0, &message, &sender); if (message != NULL) { printf("ignoring message from \"%s\": size of message: %ld\n", sender->comp_host, message->message_length); cl_com_free_message(&message); cl_com_free_endpoint(&sender); message = NULL; } else { break; } } printf("commlib cleanup ...\n"); cl_com_cleanup_commlib(); printf("main done\n"); return 0; }