/* Initialize -- Set data structure to know value, ignore current value */ int ndmis_initialize (struct ndm_session *sess) { struct ndm_image_stream *is = &sess->plumb.image_stream; NDMOS_MACRO_ZEROFILL(is); NDMOS_MACRO_ZEROFILL (&is->chan); ndmis_reinit_remote (sess); is->data_ep.name = "DATA"; is->tape_ep.name = "TAPE"; return 0; }
/* Initialize -- Set data structure to know value, ignore current value */ int ndmis_initialize (struct ndm_session *sess) { sess->plumb.image_stream = NDMOS_API_MALLOC (sizeof(struct ndm_image_stream)); if (!sess->plumb.image_stream) return -1; NDMOS_MACRO_ZEROFILL (sess->plumb.image_stream); NDMOS_MACRO_ZEROFILL (&sess->plumb.image_stream->chan); ndmis_reinit_remote (sess); sess->plumb.image_stream->data_ep.name = "DATA"; sess->plumb.image_stream->tape_ep.name = "TAPE"; return 0; }
int ndmis_tcp_close (struct ndm_session *sess) { struct ndm_image_stream *is = &sess->plumb.image_stream; switch (is->remote.connect_status) { case NDMIS_CONN_LISTEN: ndmchan_cleanup (&is->remote.listen_chan); break; case NDMIS_CONN_CONNECTED: case NDMIS_CONN_ACCEPTED: ndmchan_cleanup (&is->chan); break; default: break; } ndmis_reinit_remote (sess); return 0; }
int ndmis_ep_close (struct ndm_session *sess, struct ndmis_end_point *mine_ep, struct ndmis_end_point *peer_ep) { struct ndm_image_stream *is = &sess->plumb.image_stream; char * save_name = mine_ep->name; switch (mine_ep->connect_status) { case NDMIS_CONN_IDLE: return 0; case NDMIS_CONN_BOTCHED: case NDMIS_CONN_REMOTE: case NDMIS_CONN_EXCLUDE: goto messy; case NDMIS_CONN_LISTEN: switch (mine_ep->addr_type) { default: goto messy; case NDMP9_ADDR_LOCAL: ndmis_reinit_remote (sess); if (peer_ep->connect_status != NDMIS_CONN_IDLE) goto messy; break; case NDMP9_ADDR_TCP: ndmis_tcp_close (sess); if (peer_ep->connect_status != NDMIS_CONN_REMOTE) goto messy; peer_ep->connect_status = NDMIS_CONN_IDLE; break; } break; case NDMIS_CONN_ACCEPTED: switch (mine_ep->addr_type) { default: goto messy; case NDMP9_ADDR_LOCAL: if (peer_ep->connect_status != NDMIS_CONN_CONNECTED) goto messy; peer_ep->connect_status = NDMIS_CONN_DISCONNECTED; is->chan.eof = 1; if (mine_ep->transfer_mode == NDMCHAN_MODE_READ) is->chan.error = 1; /* EPIPE */ break; case NDMP9_ADDR_TCP: ndmis_tcp_close (sess); if (peer_ep->connect_status != NDMIS_CONN_REMOTE) goto messy; peer_ep->connect_status = NDMIS_CONN_IDLE; break; } break; case NDMIS_CONN_CONNECTED: switch (mine_ep->addr_type) { default: goto messy; case NDMP9_ADDR_LOCAL: if (peer_ep->connect_status != NDMIS_CONN_ACCEPTED) goto messy; peer_ep->connect_status = NDMIS_CONN_DISCONNECTED; is->chan.eof = 1; if (mine_ep->transfer_mode == NDMCHAN_MODE_READ) is->chan.error = 1; /* EPIPE */ break; case NDMP9_ADDR_TCP: ndmis_tcp_close (sess); if (peer_ep->connect_status != NDMIS_CONN_REMOTE) goto messy; peer_ep->connect_status = NDMIS_CONN_IDLE; break; } break; case NDMIS_CONN_DISCONNECTED: /* peer close()d first */ ndmis_reinit_remote (sess); break; case NDMIS_CONN_CLOSED: goto messy; } NDMOS_MACRO_ZEROFILL (mine_ep); mine_ep->name = save_name; return 0; messy: ndmalogf (sess, 0, 2, "close %s messy mcs=%d pcs=%d", mine_ep->name, mine_ep->connect_status, peer_ep->connect_status); NDMOS_MACRO_ZEROFILL (mine_ep); mine_ep->name = save_name; return -1; }