STCP/transport.c
void transport_init(mysocket_t sd, bool_t is_active)
{
  context_t *ctx;
  
  ctx = (context_t *) calloc(1, sizeof(context_t));
  assert(ctx);
  
  generate_initial_seq_num(ctx);
  
  /* XXX: you should send a SYN packet here if is_active, or wait for one
   * to arrive if !is_active.  after the handshake completes, unblock the
   * application with stcp_unblock_application(sd).  you may also use
   * this to communicate an error condition back to the application, e.g.
   * if connection fails; to do so, just set errno appropriately (e.g. to
   * ECONNREFUSED, etc.) before calling the function.
   */
  if (is_active) {  // Client control path, initiate connection
    // Send SYN
    if (!send_SYN(sd, ctx))
      return;
    
    // Wait for SYN-ACK
    wait_for_SYN_ACK(sd, ctx);

    // Send ACK Packet
    if (!send_ACK(sd, ctx))
      return;
    
  } else {  // Server control path, wait for connection
//    wait_for_SYN(sd, ctx);
//
//    if (!send_SYN_ACK(sd, ctx)) return;
//
//    wait_for_ACK(sd, ctx);
  }
  ctx->connection_state = CSTATE_ESTABLISHED;
  stcp_unblock_application(sd);
  
  control_loop(sd, ctx);
  
  /* do any cleanup here */
  free(ctx);
}
/* initialise the transport layer, and start the main loop, handling
 * any data from the peer or the application.  this function should not
 * return until the connection is closed.
 */
initialise the transport layer, and start the main loop, handling
any data from the peer or the application.  this function should not
return until the connection is closed.
initialise the transport layer and start the main loop handling any data from the peer or the application . this function should not return until the connection is closed .
void transport_init(mysocket_t sd, bool_t is_active)
{
  context_t *ctx;
  ctx = (context_t *) calloc(1, sizeof(context_t));
  assert(ctx);
  generate_initial_seq_num(ctx);
  if (is_active) {  
    if (!send_SYN(sd, ctx))
      return;
    wait_for_SYN_ACK(sd, ctx);
    if (!send_ACK(sd, ctx))
      return;
  } else {  
    if (!send_SYN_ACK(sd, ctx)) return;
    wait_for_ACK(sd, ctx);
  }
  ctx->connection_state = CSTATE_ESTABLISHED;
  stcp_unblock_application(sd);
  control_loop(sd, ctx);
  free(ctx);
}
void transport_init ( mysocket_t sd , bool_t is_active ) { context_t * ctx ; ctx = ( context_t * ) calloc ( 1 , sizeof ( context_t ) ) ; assert ( ctx ) ; generate_initial_seq_num ( ctx ) ; if ( is_active ) { if ( ! send_SYN ( sd , ctx ) ) return ; wait_for_SYN_ACK ( sd , ctx ) ; if ( ! send_ACK ( sd , ctx ) ) return ; } else { } ctx -> connection_state = CSTATE_ESTABLISHED ; stcp_unblock_application ( sd ) ; control_loop ( sd , ctx ) ; free ( ctx ) ; }
initialise the transport layer, and start the main loop, handling
 any data from the peer or the application.
initialise the transport layer and start the main loop handling any data from the peer or the application .
/* XXX: you should send a SYN packet here if is_active, or wait for one
   * to arrive if !is_active.  after the handshake completes, unblock the
   * application with stcp_unblock_application(sd).  you may also use
   * this to communicate an error condition back to the application, e.g.
   * if connection fails; to do so, just set errno appropriately (e.g. to
   * ECONNREFUSED, etc.) before calling the function.
   */ // Client control path, initiate connection // Send SYN // Wait for SYN-ACK // Send ACK Packet // Server control path, wait for connection //    wait_for_SYN(sd, ctx); // //    if (!send_SYN_ACK(sd, ctx)) return; // //    wait_for_ACK(sd, ctx); /* do any cleanup here */