int main (int ac, char *av[]) { int rc; int port; NDMOS_MACRO_ZEROFILL(&the_session); d_debug = -1; /* ready the_param early so logging works during process_args() */ NDMOS_MACRO_ZEROFILL (&the_param); the_param.log.deliver = ndmjob_log_deliver; the_param.log_level = d_debug; the_param.log_tag = "SESS"; the_param.config_file_name = g_strdup_printf("%s/ndmjob.conf", amdatadir); #ifndef NDMOS_OPTION_NO_CONTROL_AGENT b_bsize = 20; index_fp = stderr; o_tape_addr = -1; o_from_addr = -1; o_to_addr = -1; #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */ log_fp = stderr; if (ac != 3) proxy_usage(); /* (config arg is ignored for now) */ port = atoi(av[2]); if (!port) proxy_usage(); the_session.param = the_param; ndma_proxy_session (&the_session, port); /* run until all open connections have closed; note that * ndma_dispatch_proxy in ndma_comm_proxy.c will be called in each * quantum */ while (the_session.proxy_starting || the_session.proxy_connections > 0) { ndma_session_quantum(&the_session, 10000); } g_fprintf(stderr, "DONE\n"); /* NOTREACHED */ return 0; }
int ndmca_mon_wait_for_something (struct ndm_session *sess, int max_delay_secs) { struct ndm_control_agent *ca = sess->control_acb; int delta, notices; int time_ref = time(0) + max_delay_secs; ndmalogf (sess, 0, 5, "mon_wait_for_something() entered"); for (;;) { delta = time_ref - time(0); if (delta <= 0) break; notices = 0; if (ca->pending_notify_data_read) { /* leave visible */ notices++; } if (ca->pending_notify_data_halted) { /* just used to "wake up" */ ca->pending_notify_data_halted = 0; notices++; } if (ca->pending_notify_mover_paused) { /* leave visible */ notices++; } if (ca->pending_notify_mover_halted) { /* just used to "wake up" */ ca->pending_notify_mover_halted = 0; notices++; } ndma_session_quantum (sess, notices ? 0 : delta); if (notices) break; } ndmalogf (sess, 0, 5, "mon_wait_for_something() happened, resid=%d", delta); return 0; }
int ndma_server_session (struct ndm_session *sess, int control_sock) { struct ndmconn * conn; int rc; struct sockaddr sa; socklen_t len; rc = ndma_session_initialize (sess); if (rc) return rc; rc = ndma_session_commission (sess); if (rc) return rc; len = sizeof sa; rc = getpeername (control_sock, &sa, &len); if (rc < 0) { perror ("getpeername"); } else { char ip_addr[100]; ndmalogf (sess, 0, 2, "Connection accepted from %s", inet_ntop ( AF_INET, &(((struct sockaddr_in *)&sa)->sin_addr), ip_addr, 100)); } len = sizeof sa; rc = getsockname (control_sock, &sa, &len); if (rc < 0) { perror ("getsockname"); } else { char ip_addr[100]; ndmalogf (sess, 0, 2, "Connection accepted to %s", inet_ntop( AF_INET, &((struct sockaddr_in *)&sa)->sin_addr, ip_addr, 100)); } conn = ndmconn_initialize (0, "#C"); if (!conn) { ndmalogf (sess, 0, 0, "can't init connection"); close (control_sock); return -1; } ndmos_condition_control_socket (sess, control_sock); ndmconn_set_snoop (conn, &sess->param.log, sess->param.log_level); ndmconn_accept (conn, control_sock); conn->call = ndma_call; conn->context = sess; sess->plumb.control = conn; while (!conn->chan.eof) { ndma_session_quantum (sess, 1000); } #if 0 { char ip_addr[100]; ndmalogf (sess, 0, 2, "Connection close %s", inet_ntop( AF_INET, &((struct sockaddr_in *)&sa)->sin_addr, ip_addr, 100)); } #endif ndmconn_destruct (conn); ndma_session_decommission (sess); return 0; }