コード例 #1
0
ファイル: telemetry.cpp プロジェクト: fretelweb/audio-router
DWORD telemetry::on_routing_threadproc(LPVOID param)
{
    const int times_routed = *((int*)param);
    delete param;

    std::string host;
    SOCKET sock = try_connect(host);
    if(sock == INVALID_SOCKET)
    {
        host.clear();
        return 0;
    }

    std::string path;
    xor(path, path_routed_xor, sizeof(path_routed_xor));

    if(times_routed == 0)
        try_send(sock, host, path, "routed_0");
    else if(times_routed == 9)
        try_send(sock, host, path, "routed_9");
    else
        try_send(sock, host, path, "routed");

    path.clear();
    host.clear();
    closesocket(sock);
    return 0;
}
コード例 #2
0
void PipelineSchedulingHost::handle_offer_pkt(OfferPkt* offer_pkt, FountainFlowWithPipelineSchedulingHost* f)
{

   if(offer_pkt->is_free){
       if(debug_host(this->id) || debug_flow(f->id))
           std::cout << get_current_time() << " host " << this->id << " got offer for flow "
           << offer_pkt->flow->id << " curr_iter:" << this->sender_iteration << " pkt_iter:" << offer_pkt->iter << "\n";
       //accept
       if(this->sender_iteration == offer_pkt->iter && (current_sending_flow == NULL || next_sending_flow == NULL)){
           f->scheduled = true;
           f->remaining_schd_pkt = std::max((int)1, std::min((int)params.reauth_limit, (int)(f->size_in_pkt - f->total_pkt_sent)));

           this->sender_schedule_state = 0;
           this->sender_iteration++;
           this->sender_rej_received_count = 0;
           this->sender_rts_sent_count = 0;

           if(current_sending_flow)
           {
               assert(this->next_sending_flow == NULL);
               this->next_sending_flow = (FountainFlowWithPipelineSchedulingHost*)offer_pkt->flow;
               this->sender_busy_until = get_current_time() + 1500*8/params.bandwidth * this->next_sending_flow->remaining_schd_pkt;
               if(debug_host(this->id))
                   std::cout << get_current_time() << " host " << this->id << " set next sending flow " <<
                       this->next_sending_flow->id << " curr_sending_flow:" << this->current_sending_flow->id << "\n";
           }
           else
           {
               if(debug_host(this->id)) std::cout << get_current_time() << " host " << this->id << " set current sending flow to " << offer_pkt->flow->id << "\n";
               this->current_sending_flow = (FountainFlowWithPipelineSchedulingHost*)offer_pkt->flow;
               this->sender_busy_until = get_current_time() + 1500*8/params.bandwidth * this->current_sending_flow->remaining_schd_pkt;
               this->try_send();
           }
       }
       //reject
       else if(this->sender_iteration < offer_pkt->iter){
           assert(false);
       }
       else{
           DecisionPkt* decision = new DecisionPkt(f, offer_pkt->src, offer_pkt->dst, false);
       }
   }else{
       if(this->sender_iteration == offer_pkt->iter){
           this->sender_rej_received_count++;

           if(sender_rej_received_count == sender_rts_sent_count){
               this->sender_iteration++;
               this->sender_rej_received_count = 0;
               this->sender_schedule_state = 0;
               if(debug_host(this->id)) std::cout << get_current_time() << " host " << this->id << " reset state\n";
               try_send();
           }
       }



   }


}
コード例 #3
0
ファイル: messaging.c プロジェクト: 0x24bin/winexe-1
/*
  handle a socket write event
*/
static void messaging_send_handler(struct messaging_context *msg)
{
	while (msg->pending) {
		struct messaging_rec *rec = msg->pending;
		NTSTATUS status;
		status = try_send(rec);
		if (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
			rec->retries++;
			if (rec->retries > 3) {
				/* we're getting continuous write errors -
				   backoff this record */
				DLIST_REMOVE(msg->pending, rec);
				DLIST_ADD_END(msg->retry_queue, rec, 
					      struct messaging_rec *);
				if (msg->retry_te == NULL) {
					msg->retry_te = 
						event_add_timed(msg->event.ev, msg, 
								timeval_current_ofs(1, 0), 
								msg_retry_timer, msg);
				}
			}
			break;
		}
		rec->retries = 0;
		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(1,("messaging: Lost message from %s to %s of type %u - %s\n", 
				 cluster_id_string(debug_ctx(), rec->header->from), 
				 cluster_id_string(debug_ctx(), rec->header->to), 
				 rec->header->msg_type, 
				 nt_errstr(status)));
		}
		DLIST_REMOVE(msg->pending, rec);
		talloc_free(rec);
	}
コード例 #4
0
ファイル: rconn.c プロジェクト: ecks/harry
/* Sends 'b' on 'rc'.  Returns 0 if successful, or ENOTCONN if 'rc' is not
 * currently connected.  Takes ownership of 'b'.
 *
 * If 'counter' is non-null, then 'counter' will be incremented while the
 * packet is in flight, then decremented when it has been sent (or discarded
 * due to disconnection).  Because 'b' may be sent (or discarded) before this
 * function returns, the caller may not be able to observe any change in
 * 'counter'.
 *
 * There is no rconn_send_wait() function: an rconn has a send queue that it
 * takes care of sending if you call rconn_run(), which will have the side
 * effect of waking up poll_block(). */
int
rconn_send(struct rconn *rc, struct rfpbuf *b)
{
    if (rconn_is_connected(rc)) {
            try_send(rc, b);
        return 0;
    } else {
        return ENOTCONN;
    }
}
コード例 #5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
  static int connected = 0;
  static session_t dst;

  PROCESS_BEGIN();

  dtls_init();

  init_dtls(&dst);
  serial_line_init();

  if (!dtls_context) {
    dsrv_log(LOG_EMERG, "cannot create context\n");
    PROCESS_EXIT();
  }

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      dtls_handle_read(dtls_context);
    } else if (ev == serial_line_event_message) {
      register size_t len = min(strlen(data), sizeof(buf) - buflen);
      memcpy(buf + buflen, data, len);
      buflen += len;
      if (buflen < sizeof(buf) - 1)
	buf[buflen++] = '\n';	/* serial event does not contain LF */
    }

    if (buflen) {
      if (!connected)
	connected = dtls_connect(dtls_context, &dst) >= 0;
      
      try_send(dtls_context, &dst);
    }
  }
  
  PROCESS_END();
}
コード例 #6
0
void try_send_all(connection_t *c)
{
    /*  debug( 3,
           L"Send all updates to connection on fd %d",
           c->fd );*/
    while (!c->unsent->empty())
    {
        switch (try_send(c->unsent->front(), c->fd))
        {
            case 1:
                c->unsent->pop();
                break;

            case 0:
                debug(4,
                      L"Socket full, send rest later");
                return;

            case -1:
                c->killme = 1;
                return;
        }
    }
}
コード例 #7
0
ファイル: dtls-client.c プロジェクト: ezhangle/tinydtls-code
int 
main(int argc, char **argv) {
  dtls_context_t *dtls_context = NULL;
  fd_set rfds, wfds;
  struct timeval timeout;
  unsigned short port = DEFAULT_PORT;
  char port_str[NI_MAXSERV] = "0";
  log_t log_level = LOG_WARN;
  int fd, result;
  int on = 1;
  int opt, res;
  session_t dst;

  dtls_init();
  snprintf(port_str, sizeof(port_str), "%d", port);

  while ((opt = getopt(argc, argv, "p:o:v:")) != -1) {
    switch (opt) {
    case 'p' :
      strncpy(port_str, optarg, NI_MAXSERV-1);
      port_str[NI_MAXSERV - 1] = '\0';
      break;
    case 'o' :
      output_file.length = strlen(optarg);
      output_file.s = (unsigned char *)malloc(output_file.length + 1);
      
      if (!output_file.s) {
	dsrv_log(LOG_CRIT, "cannot set output file: insufficient memory\n");
	exit(-1);
      } else {
	/* copy filename including trailing zero */
	memcpy(output_file.s, optarg, output_file.length + 1);
      }
      break;
    case 'v' :
      log_level = strtol(optarg, NULL, 10);
      break;
    default:
      usage(argv[0], PACKAGE_VERSION);
      exit(1);
    }
  }

  set_log_level(log_level);
  
  if (argc <= optind) {
    usage(argv[0], PACKAGE_VERSION);
    exit(1);
  }
  
  memset(&dst, 0, sizeof(session_t));
  /* resolve destination address where server should be sent */
  res = resolve_address(argv[optind++], &dst.addr.sa);
  if (res < 0) {
    dsrv_log(LOG_EMERG, "failed to resolve address\n");
    exit(-1);
  }
  dst.size = res;

  /* use port number from command line when specified or the listen
     port, otherwise */
  dst.addr.sin.sin_port = htons(atoi(optind < argc ? argv[optind++] : port_str));

  
  /* init socket and set it to non-blocking */
  fd = socket(dst.addr.sa.sa_family, SOCK_DGRAM, 0);

  if (fd < 0) {
    dsrv_log(LOG_ALERT, "socket: %s\n", strerror(errno));
    return 0;
  }

  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on) ) < 0) {
    dsrv_log(LOG_ALERT, "setsockopt SO_REUSEADDR: %s\n", strerror(errno));
  }
#if 0
  flags = fcntl(fd, F_GETFL, 0);
  if (flags < 0 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
    dsrv_log(LOG_ALERT, "fcntl: %s\n", strerror(errno));
    goto error;
  }
#endif
  on = 1;
#ifdef IPV6_RECVPKTINFO
  if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof(on) ) < 0) {
#else /* IPV6_RECVPKTINFO */
  if (setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &on, sizeof(on) ) < 0) {
#endif /* IPV6_RECVPKTINFO */
    dsrv_log(LOG_ALERT, "setsockopt IPV6_PKTINFO: %s\n", strerror(errno));
  }

  dtls_context = dtls_new_context(&fd);
  if (!dtls_context) {
    dsrv_log(LOG_EMERG, "cannot create context\n");
    exit(-1);
  }

  dtls_set_handler(dtls_context, &cb);

  dtls_connect(dtls_context, &dst);

  while (1) {
    FD_ZERO(&rfds);
    FD_ZERO(&wfds);

    FD_SET(fileno(stdin), &rfds);
    FD_SET(fd, &rfds);
    /* FD_SET(fd, &wfds); */
    
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    
    result = select(fd+1, &rfds, &wfds, 0, &timeout);
    
    if (result < 0) {		/* error */
      if (errno != EINTR)
	perror("select");
    } else if (result == 0) {	/* timeout */
    } else {			/* ok */
      if (FD_ISSET(fd, &wfds))
	/* FIXME */;
      else if (FD_ISSET(fd, &rfds))
	dtls_handle_read(dtls_context);
      else if (FD_ISSET(fileno(stdin), &rfds))
	handle_stdin();
    }

    if (len)
      try_send(dtls_context, &dst);
  }
  
  dtls_free_context(dtls_context);
  exit(0);
}
コード例 #8
0
void PipelineSchedulingHost::start(Flow* f) {
    this->sending_flows.push(f);
    try_send();
}
コード例 #9
0
ファイル: L2_cache.cpp プロジェクト: sixshotx/manifold
//! This function is scheduled by send_msg_to_l1(), get_from_memory(), and dirty_to_memory()
//! to send the message after a delay of lookup_time
void L2_cache :: send_msg_after_lookup_time(NetworkPacket* pkt)
{
    m_downstream_output_buffer.push_back(pkt);
    try_send();
}
コード例 #10
0
ファイル: udt_socket.cpp プロジェクト: xiaojianwu/turbolib
int udt_socket::send(const char* buffer, unsigned size)
{
	UdtAsyncOff sync(_sock);
	return try_send(buffer, size);
}
コード例 #11
0
ファイル: udt_socket.cpp プロジェクト: xiaojianwu/turbolib
int udt_socket::try_send(const std::string& buffer)
{
	return try_send(buffer.data(), buffer.size());
}