Ejemplo n.º 1
0
//static int run(int argc, char **argv)
int ibrdma_send(char* host, char* port, void* data, uint64_t size)
{
  
  struct addrinfo *addr;
  struct rdma_cm_id *cmid= NULL;
  struct rdma_event_channel *ec = NULL;
  struct rdma_conn_param cm_params;
  TEST_NZ(getaddrinfo(host, port, NULL, &addr));
  TEST_Z(ec = rdma_create_event_channel());
  TEST_NZ(rdma_create_id(ec, &cmid, NULL, RDMA_PS_TCP));
  TEST_NZ(rdma_resolve_addr(cmid, NULL, addr->ai_addr, TIMEOUT_IN_MS));
  TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_ADDR_RESOLVED));
  freeaddrinfo(addr);
  build_connection(cmid);
  TEST_NZ(rdma_resolve_route(cmid, TIMEOUT_IN_MS));
  TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_ROUTE_RESOLVED));
  build_params(&cm_params);
  TEST_NZ(rdma_connect(cmid, &cm_params));
  TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_ESTABLISHED));
  on_connect(cmid->context);

  /* Init MSG send to start RDMA*/
  init_tfile(data,  size);
  send_init(cmid->context);
  /*----------------------------*/

  TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_DISCONNECTED));
  rdma_destroy_id(cmid);
  rdma_destroy_event_channel(ec);

  return 0;
}
Ejemplo n.º 2
0
//static int run(int argc, char **argv)
//int RDMA_Connect(struct RDMA_communicator *comm, struct RDMA_param *param)
int RDMA_Active_Init(struct RDMA_communicator *comm, struct RDMA_param *param)
{
  struct addrinfo *addr;
  //  struct rdma_cm_id *cm_id= NULL;
  //  struct rdma_event_channel *ec = NULL;
  struct rdma_conn_param cm_params;
  char port[8];
  //  int i,j;

  sprintf(port, "%d", RDMA_PORT);

  TEST_NZ(getaddrinfo(param->host, port, NULL, &addr));

  TEST_Z(comm->ec = rdma_create_event_channel());

  TEST_NZ(rdma_create_id(comm->ec, &(comm->cm_id), NULL, RDMA_PS_TCP));
  TEST_NZ(rdma_resolve_addr(comm->cm_id, NULL, addr->ai_addr, TIMEOUT_IN_MS));
  TEST_NZ(wait_for_event(comm->ec, RDMA_CM_EVENT_ADDR_RESOLVED));
  freeaddrinfo(addr);

  build_connection(comm->cm_id);
  TEST_NZ(rdma_resolve_route(comm->cm_id, TIMEOUT_IN_MS));
  TEST_NZ(wait_for_event(comm->ec, RDMA_CM_EVENT_ROUTE_RESOLVED));
  build_params(&cm_params);
  TEST_NZ(rdma_connect(comm->cm_id, &cm_params));
  TEST_NZ(wait_for_event(comm->ec, RDMA_CM_EVENT_ESTABLISHED));
  //  on_connect(cm_id->context);

  return 0;
}
Ejemplo n.º 3
0
int ibrdma_transfer(struct transfer_info *tfi, int num_tfi) {
  struct addrinfo *addr;
  struct rdma_cm_id *cmid= NULL;
  struct rdma_event_channel *ec = NULL;
  struct rdma_conn_param cm_params;
  TEST_NZ(getaddrinfo(host, port, NULL, &addr));
  TEST_Z(ec = rdma_create_event_channel());
  TEST_NZ(rdma_create_id(ec, &cmid, NULL, RDMA_PS_TCP));
  TEST_NZ(rdma_resolve_addr(cmid, NULL, addr->ai_addr, TIMEOUT_IN_MS));
  TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_ADDR_RESOLVED));
  freeaddrinfo(addr);
  build_connection(cmid);
  TEST_NZ(rdma_resolve_route(cmid, TIMEOUT_IN_MS));
  TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_ROUTE_RESOLVED));
  build_params(&cm_params);
  TEST_NZ(rdma_connect(cmid, &cm_params));
  TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_ESTABLISHED));
  on_connect(cmid->context);
  


  TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_DISCONNECTED));
  rdma_destroy_id(&cmid);
  rdma_destroy_event_channel(&ec);

  return 0;
}
Ejemplo n.º 4
0
static void worker_cb(int fd, short flags, void *arg)
{
	struct Worker *w = arg;
	const char *err;
	char buf[128];
	int res;
	size_t outlen;

	w->pending = 0;

	if (w->wstate == HANDSHAKE) {
		err = do_handshake(w, fd);
		add_error(w, err);
	} else if (w->wstate == CONNECTED) {
		if (flags & EV_READ) {
			res = tls_read(w->ctx, buf, sizeof buf, &outlen);
			if (res == TLS_READ_AGAIN) {
				wait_for_event(w, EV_READ);
			} else if (res == TLS_WRITE_AGAIN) {
				wait_for_event(w, EV_WRITE);
			} else if (res == 0) {
				if (outlen > 0 && w->is_server) {
					tls_write(w->ctx, "END", 3, &outlen);
					w->wstate = CLOSED;
				} else if (outlen == 0) {
					w->wstate = CLOSED;
				} else {
					wait_for_event(w, EV_READ);
				}
			} else {
				add_error(w, "bad pkt");
			}
		} else {
			add_error(w, "EV_WRITE?");
		}
	}
	if (w->wstate == CLOSED && w->ctx) {
		res = tls_close(w->ctx);
		if (res == 0) {
			tls_free(w->ctx);
			w->ctx = NULL;
		} else if (res == TLS_READ_AGAIN) {
			wait_for_event(w, EV_READ);
		} else if (res == TLS_WRITE_AGAIN) {
			wait_for_event(w, EV_WRITE);
		} else {
			tls_free(w->ctx);
			w->ctx = NULL;
		}
	}
	if (!w->pending && w->ctx) {
		errx(1, "missed event setup: %s flags=%d state=%d", w->is_server ? "S":"C", flags, w->wstate);
	}
	return;
}
Ejemplo n.º 5
0
void run_code_event(struct state *state, struct event *event,
			    const char *text)
{
	DEBUGP("%d: run code event\n", event->line_number);

	char *error = NULL;

	/* Wait for the right time before firing off this event. */
	wait_for_event(state);

	//TODO modify to support multi socket support
	/*
	 * Idea: extend event struct to put a socked_fd and get this fd from
	 * the script (thus specified by user)?
	 *
	 */
	if (state->socket_under_test == NULL) {
		asprintf(&error, "no socket to use for code");
		goto error_out;
	}
	int fd = state->socket_under_test->live.fd;
	struct code_state *code = state->code;

	void *data = NULL;
	int  data_len = 0;
	if (code->data_type == DATA_NONE) {
		/* First time: try various getsockopt calls until one works. */
#if HAVE_TCP_INFO
		if (data == NULL) {
			code->data_type = DATA_TCP_INFO;
			data = get_data(fd, code->data_type, &data_len);
		}
#endif  /* HAVE_TCP_INFO */
		if (data == NULL) {
			asprintf(&error,
				 "can't find getsockopt to get TCP info");
			goto error_out;
		}
	} else {
		/* Run the getsockopt we already picked above. */
		data = get_data(fd, code->data_type, &data_len);
		if (!data) {
			asprintf(&error, "can't get info for socket");
			goto error_out;
		}
	}
	assert(code->data_type != DATA_NONE);
	assert(data != NULL);

	append_data(code, code->data_type, data, data_len);
	append_text(code, state->config->script_path, event->line_number,
		    strdup(text));

	return;

error_out:
	die("%s:%d: runtime error in code: %s\n",
	    state->config->script_path, event->line_number, error);
	free(error);
}
Ejemplo n.º 6
0
static const char *done_handshake(struct Worker *w)
{
	int res;
	size_t outlen = 0;
	const char *emsg;

	emsg = check_fp(w, "sha1", w->peer_fingerprint_sha1, 20);
	if (emsg)
		return emsg;
	emsg = check_fp(w, "sha256", w->peer_fingerprint_sha256, 32);
	if (emsg)
		return emsg;

	if (w->show) {
		if (strcmp(w->show, "ciphers") == 0) {
			tls_get_connection_info(w->ctx, w->showbuf, sizeof w->showbuf);
		} else if (strcmp(w->show, "peer-cert") == 0) {
			struct tls_cert *cert = NULL;
			tls_get_peer_cert(w->ctx, &cert, NULL);
			show_cert(cert, w->showbuf, sizeof w->showbuf);
			tls_cert_free(cert);
		} else {
			snprintf(w->showbuf, sizeof w->showbuf, "bad kw: show=%s", w->show);
		}
	}

	if (!w->is_server) {
		res = tls_write(w->ctx, "PKT", 3, &outlen);
		if (res != 0 && outlen != 3)
			return "write!=3";
	}
	return wait_for_event(w, EV_READ);
}
Ejemplo n.º 7
0
extern void unmake_timer_thread(void)
{
  CONTEXT timer_thread_context;
  BOOL result;
  DIAGNOSTIC(2,"unmaking timer thread",0,0);
  suspend_thread(timer_thread);
  DIAGNOSTIC(3,"timer thread suspended",0,0);
  timer_thread_context.ContextFlags = CONTEXT_CONTROL;
  result = GetThreadContext((HANDLE)timer_thread,
			    &timer_thread_context);
  if (result == FALSE)
    error("GetThreadContext(timer) failed; GetLastError() returns %d",
	  GetLastError());
  DIAGNOSTIC(3,"timer thread context obtained",0,0);
  timer_thread_context.Eip = (DWORD)timer_thread_end;
  result = SetThreadContext((HANDLE)timer_thread,
			    &timer_thread_context);
  if (result == FALSE)
    error("SetThreadContext(timer) failed; GetLastError() returns %d",
	  GetLastError());
  DIAGNOSTIC(3,"timer thread context set",0,0);
  set_event(timer_event);
  DIAGNOSTIC(3,"timer event set",0,0);
  resume_thread(timer_thread);
  DIAGNOSTIC(3,"timer thread resumed",0,0);
  wait_for_event(timer_thread);
  DIAGNOSTIC(3,"timer thread signalled",0,0);
  close_handle(timer_thread);
  close_handle(timer_event);
  DIAGNOSTIC(2,"timer thread unmade and forgotten",0,0);
}
 bool pin_edge_event::signalled() const
 {
   timespec ts;
   ts.tv_sec = 0L;
   ts.tv_nsec = 0L;
   return wait_for_event(pin_event_fd, &ts)==1;
 }
Ejemplo n.º 9
0
/* ***************************************************
 * Function: send_syn_ack
 * ***************************************************
 * Passive node calls this to send SYN_ACK and wait for
 * the final ACK packet. It tries a total of 6 times before
 * giving up.
 */
static bool send_syn_ack(mysocket_t sd, context_t *ctx, struct tcphdr* syn_packet)
{
	struct tcphdr* ack_packet = (struct tcphdr *)calloc(1,(TH_MAX_OFFSET*sizeof(uint32_t))+STCP_MSS);
	unsigned int event;
	bool success = false;
	int num_tries = 1;
	struct timeval tstart;
	gettimeofday(&tstart, NULL); /*Start the timer */
	network_send(sd, syn_packet, (TH_MIN_OFFSET*sizeof(uint32_t)));
	while((num_tries < MAX_RT_TRIES) && !success){
		event = wait_for_event(sd, NETWORK_DATA, ctx, tstart);
		if (event & NETWORK_DATA) {
			network_recv(sd, ack_packet);
			our_dprintf("Passive (ACK waiting): Ack: %d, Seq:%d, Next Seq:%d, Last Ack Sent: %d\n", 
						 ack_packet->th_ack, ack_packet->th_seq, ctx->nxt_seq_num, ctx->last_ack_sent);
			success =  ((ack_packet->th_flags == TH_ACK) &&
						(ack_packet->th_ack == ctx->nxt_seq_num));
		}
		else if (event==TIMEOUT){
			our_dprintf("Passive Final INIT ACK not Received TIMEOUT!\n");	
			num_tries+=1;
			gettimeofday(&tstart, NULL);
			our_dprintf("PASSIVE - SEND SYN_ACK Packet with seq: %d and ack: %d \n",
						 syn_packet->th_seq, syn_packet->th_ack);
			network_send(sd, syn_packet, (TH_MIN_OFFSET*sizeof(uint32_t)));
		}
	}
	if (success){
		our_dprintf("PASSIVE - RCVD Last Ack Packet has seq: %d and ack: %d \n",
					 ack_packet->th_seq, ack_packet->th_ack);
   		ctx->recv_win = MIN(syn_packet->th_win, CWIN);
	}	
	free(ack_packet);
	return success;
}
Ejemplo n.º 10
0
static int fio_solarisaio_getevents(struct thread_data *td, unsigned int min,
				    unsigned int max, struct timespec *t)
{
	struct solarisaio_data *sd = td->io_ops->data;
	struct timeval tv;
	int ret;

	if (!min || !t) {
		tv.tv_sec = 0;
		tv.tv_usec = 0;
	} else {
		tv.tv_sec = t->tv_sec;
		tv.tv_usec = t->tv_nsec / 1000;
	}

	while (sd->aio_pending < min)
		wait_for_event(&tv);

	/*
	 * should be OK without locking, as int operations should be atomic
	 */
	ret = sd->aio_pending;
	sd->aio_pending -= ret;
	return ret;
}
Ejemplo n.º 11
0
int RDMA_Active_Finalize(struct RDMA_communicator *comm)
{
  TEST_NZ(wait_for_event(comm->ec, RDMA_CM_EVENT_DISCONNECTED));
  rdma_destroy_id(comm->cm_id);
  rdma_destroy_event_channel(comm->ec);
  return 0;
}
Ejemplo n.º 12
0
static void send_create_event (flux_t h, int64_t id, char *topic)
{
    flux_msg_t *msg;
    char *json = NULL;

    if (asprintf (&json, "{\"lwj\":%ld}", id) < 0) {
        errno = ENOMEM;
        flux_log_error (h, "failed to create state change event");
        goto out;
    }
    if ((msg = flux_event_encode (topic, json)) == NULL) {
        flux_log_error (h, "failed to create state change event");
        goto out;
    }
    if (flux_send (h, msg, 0) < 0)
        flux_log_error (h, "reserved event failed");
    flux_msg_destroy (msg);

    /* Workaround -- wait for our own event to be published with a
     *  blocking recv. XXX: Remove when publish is synchronous.
     */
    wait_for_event (h, id, topic);
out:
    free (json);
}
Ejemplo n.º 13
0
CP_HIDDEN void cpi_wait_mutex(cpi_mutex_t *mutex) {
	DWORD self = GetCurrentThreadId();

	assert(mutex != NULL);
	lock_mutex(mutex->os_mutex);
	if (mutex->lock_count > 0
		&& self == mutex->os_thread) {
		int lc = mutex->lock_count;

		// Release mutex
		mutex->lock_count = 0;
		mutex->num_wait_threads++;
		set_event(mutex->os_cond_lock);
		unlock_mutex(mutex->os_mutex);

		// Wait for signal
		wait_for_event(mutex->os_cond_wake);

		// Reset wake signal if last one waking up
		lock_mutex(mutex->os_mutex);
		if (--mutex->num_wait_threads == 0) {
			reset_event(mutex->os_cond_wake);
		}

		// Re-acquire mutex and restore lock count for this thread
		lock_mutex_holding(mutex);
		mutex->lock_count = lc;

	} else {
		cpi_fatalf(_("Internal C-Pluff error: Unauthorized attempt at waiting on a mutex."));
	}
	unlock_mutex(mutex->os_mutex);
}
Ejemplo n.º 14
0
void
GameSession::levelintro(void)
{
  music_manager->halt_music();
  
  char str[60];
 
  if (get_level()->img_bkgd)
    get_level()->img_bkgd->draw(0, 0);
  else
    drawgradient(get_level()->bkgd_top, get_level()->bkgd_bottom);

  sprintf(str, "%s", world->get_level()->name.c_str());
  gold_text->drawf(str, 0, 200, A_HMIDDLE, A_TOP, 1);

  sprintf(str, "TUX x %d", player_status.lives);
  white_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1);
  
  sprintf(str, "by %s", world->get_level()->author.c_str());
  white_small_text->drawf(str, 0, 360, A_HMIDDLE, A_TOP, 1);
  

  flipscreen();

  SDL_Event event;
  wait_for_event(event,1000,3000,true);
}
Ejemplo n.º 15
0
/* ***************************************************
 * Function: control_wait
 * ***************************************************
 * This function determines the right event to wait for based on window size
 * and connection state.
 * If the window is full, then we don't wait for application data as we know
 * we can't send any.
 * If there are bytes outstanding (not-acked), then we need to wait using a timeout
 * value.
 * If we are TIME_WAIT state, then we set the RTO to the TIME_WAIT_VALUE and only accept
 * network data (i.e. FIN that need to be acknowledged).
 */
unsigned int control_wait(mysocket_t sd, context_t *ctx, bool fin_retry)
{
	unsigned int event = 0;
	size_t bytes_in_transit = ctx->nxt_seq_num - ctx->seq_base;
  	size_t win_space = ctx->recv_win - bytes_in_transit;
  		
	unsigned int wait_flags = NETWORK_DATA | APP_CLOSE_REQUESTED;
	if (win_space >0 && !fin_retry) {
		wait_flags |= APP_DATA;	
	}
	/* Is there something in flight? */
	if (bytes_in_transit > 0) {
		assert((ctx->sbuffer.num_entries>0) || !DEBUG);
		our_dprintf("Waiting with RTO for Seq:%d \n", ctx->seq_base);
		event = wait_with_rto(sd, wait_flags, ctx); 
	}
	else if (ctx->connection_state==CSTATE_TIME_WAIT) {
		ctx->rto = TIME_WAIT_VALUE;
		struct timeval current_time;
		gettimeofday(&current_time, NULL);
		our_dprintf("IN TIME WAIT!!!\n");
		event = wait_for_event(sd, NETWORK_DATA, ctx,current_time);    			
	}
	else {
		/* No unacked packets... take your sweet time*/
		event = stcp_wait_for_event(sd, ANY_EVENT, NULL);
	}
	return event;	
}
Ejemplo n.º 16
0
void sender3(void)
{
  seq_nr next_frame_to_send;	/* seq number of next outgoing frame */
  frame s;		/* scratch variable */
  packet buffer;	/* buffer for an outbound packet */
  event_type event;

  next_frame_to_send = 0;	/* initialize outbound sequence numbers */
  from_network_layer(&buffer);	/* fetch first packet */
  while (true) {
        init_frame(&s);
        s.info = buffer;	/* construct a frame for transmission */
        s.seq = next_frame_to_send;	/* insert sequence number in frame */
        to_physical_layer(&s);	/* send it on its way */
        start_timer(s.seq);	/* if answer takes too long, time out */
        wait_for_event(&event);	/* frame_arrival, cksum_err, timeout */
        if (event == frame_arrival) {
                from_physical_layer(&s);	/* get the acknowledgement */
                if (s.ack == next_frame_to_send) {
                        from_network_layer(&buffer);	/* get the next one to send */
                        inc(next_frame_to_send);	/* invert next_frame_to_send */
                }
        }
  }
}
Ejemplo n.º 17
0
void
start_event_loop (void)
{
  /* Loop until there is nothing to do.  This is the entry point to
     the event loop engine.  If nothing is ready at this time, wait
     for something to happen (via wait_for_event), then process it.
     Return when there are no longer event sources to wait for.  */

  while (1)
    {
      /* Any events already waiting in the queue?  */
      if (process_event ())
	continue;

      /* Wait for a new event.  If wait_for_event returns -1, we
	 should get out because this means that there are no event
	 sources left.  This will make the event loop stop, and the
	 application exit.  */

      if (wait_for_event () < 0)
	return;
    }

  /* We are done with the event loop.  There are no more event sources
     to listen to.  So we exit gdbserver.  */
}
 bool pin_edge_event::wait_(long t_rel_secs, long t_rel_ns) const
 {
   timespec ts;
   ts.tv_sec = t_rel_secs;
   ts.tv_nsec = t_rel_ns;
   return wait_for_event(pin_event_fd, &ts)==1;
 }
Ejemplo n.º 19
0
/* ***************************************************
 * Function: wait_with_rto
 * ***************************************************
 * 	Wrapper function for wait_for_event that uses the time
 *  that the packet in the head of the window was sent
 *  as the starting time.
 */
static unsigned int wait_with_rto(mysocket_t sd, 
					unsigned int wait_flags, context_t *ctx)
{
	assert(ctx->sbuffer.start->next || !DEBUG);
	struct timeval start_time = ctx->sbuffer.start->next->tstart;
	unsigned int event = wait_for_event(sd, wait_flags, ctx, start_time); 
	return event;
}
Ejemplo n.º 20
0
static const char *do_handshake(struct Worker *w, int fd)
{
	int err;
	const char *msg;

	err = tls_handshake(w->ctx);
	if (err == TLS_WANT_POLLIN) {
		return wait_for_event(w, EV_READ);
	} else if (err == TLS_WANT_POLLIN) {
		return wait_for_event(w, EV_WRITE);
	} else if (err == 0) {
		w->wstate = CONNECTED;
		return done_handshake(w);
	}
	msg = tls_error(w->ctx ? w->ctx : w->base);
	return msg ? msg : "handshake failure";
}
int main(int argc, char* argv[]) {
    parse_options(argc, argv);
    // Daemonize, unless we're passed -d
    if(daemonize) {
	pid_t pid = fork();
	if(pid < 0) {
	    fprintf(stderr, "Fork failed with %d\n", pid);
	} else if(pid > 0) {
	    return EXIT_SUCCESS; // child has forked off correctly, we terminate immediately.
	}
    }

    // we will be sent a USR1 by acpid when the power adapter is plugged/unplugged. at that point we reread its state.
    // this approach saves us from having to poll that every few seconds to see if it's changed
    // (one of the few places where it's practical to avoid polling)
    signal(SIGUSR1, refresh_adapter_state);

    XScreenSaverInfo* info = XScreenSaverAllocInfo();
    info->idle = 0; // ensure this is initialised since we'll calculate on it shortly
    Display* display = XOpenDisplay(0);
    if(display == NULL) {
        fprintf(stderr, "Couldn't connect to X display\n");
        return EXIT_FAILURE;
    }

    // do some initial updates to make sure everything's been read at first
    // this will set the initial brightness values for us as well
    refresh_adapter_state();
    update_light_sensor();

    // NB. ideally we would use select() or something to wait for the applesmc sysfs entry
    //     to change, but it doesn't seem to work. Not sure that's possible on this kind of hardware sensor?

    while(1) {
        // we've just gone idle. wait in 2 second chunks to keep checking the light sensor
        int i;
	for(i = 0; i < time_before_dim * 1000 - info->idle; i += 2000) {
	    sleep(2);
	    update_light_sensor();
	    dprintf("Time until dimming planned to begin: %ld\n", time_before_dim - info->idle/1000 - i/1000);
	}
	// now check the idle time again
        XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
	if(info->idle < time_before_dim*1000) {
	    // we must have been woken in between. go back to waiting.
	    continue;
	}

	// here we have waited the requisite amount of time. dim the display.
	dprintf("Dimming display\n");
	if(!continuous_dim_backlight(display, info)) {
	    wait_for_event(display, info);
	}
	// once we get here, we are undimming because something's happened
	is_dimmed = 0;
	adjust_brightness(1.0);
    }
}
Ejemplo n.º 22
0
static void native_thread_run(struct c_state *c_state)
{
  void (*continuation)(void);
  DIAGNOSTIC(2,"starting new native thread, waiting for event",0,0);
  wait_for_event(c_state->native.event);
  continuation = (void (*)(void))c_state->eip;
  DIAGNOSTIC(3,"in new thread, calling continuation 0x%x",continuation,0);
  continuation();
}
Ejemplo n.º 23
0
void uart_tx_worker(void *parg)
  {
  uart_config_t *uart = (uart_config_t *) parg;

  while(true)
    {
    if(uart->tx_worker_offset >= uart->tx_length)
      {
      // wait for a queued message
      pop_front(&uart->tx_queue, uart->tx_worker_buffer, INDEFINITE_WAIT);
      uart->tx_worker_offset = 0;
      }
    
    while(uart->tx_worker_offset < uart->tx_length)
      {
      bool should_block = false;
      uint8_t ch;
      
      if(uart->uart_number == 1)
        {
        while(U1STAbits.UTXBF == 1)
          wait_for_event(&uart->uart_tx_ready, 1);
        }
      else
        {
        while(U2STAbits.UTXBF == 1)
          wait_for_event(&uart->uart_tx_ready, 1);
        }

      ch = uart->tx_worker_buffer[uart->tx_worker_offset++];
      if(uart->uart_number == 1)
        U1TXREG = ch;
      else
        U2TXREG = ch;
      
      if(uart->flags & UART_EOL_CHAR && ch == uart->eol_char)
        {
        // flag end of buffer.
        uart->tx_worker_offset = uart->tx_length;
        break;
        }
      }
    }
  }
Ejemplo n.º 24
0
static const char *do_handshake(struct Worker *w, int fd)
{
	int err;
	const char *msg;
	if (w->is_server) {
		err = tls_accept_socket(w->base, &w->ctx, fd);
	} else {
		err = tls_connect_socket(w->ctx, fd, w->hostname);
	}
	if (err == TLS_READ_AGAIN) {
		return wait_for_event(w, EV_READ);
	} else if (err == TLS_WRITE_AGAIN) {
		return wait_for_event(w, EV_WRITE);
	} else if (err == 0) {
		w->wstate = CONNECTED;
		return done_handshake(w);
	}
	msg = tls_error(w->ctx ? w->ctx : w->base);
	return msg ? msg : "handshake failure";
}
Ejemplo n.º 25
0
int
tracer(pid_t child_pid) {
	int status;
	struct user_regs_struct regs;
	// wait for child to call TRACEME
	waitpid(child_pid, &status, 0);
	// intrument program with breakpoints
	fprintf(stderr, "waiting for exec");
	ptrace(PTRACE_SETOPTIONS, child_pid, 0, PTRACE_O_TRACEEXEC);
	// waitpid(child_pid, &status, 0);
	if (wait_for_event(child_pid) != 0); // lol :)
	fprintf(stderr, "writing trap");
	// write trap
	ptrace(PTRACE_POKETEXT, child_pid, 0x0000000000400511, 0xcc);
	for(int i = 0; i < 4; ++i) {
        if (wait_for_event(child_pid) != 0) break;
        ptrace(PTRACE_GETREGS, child_pid, NULL, &regs);
        fprintf(stderr, "breakpoint reached RIP is %lld\n", regs.rip);
    }
    return (0);
}
Ejemplo n.º 26
0
static void lock_mutex_holding(cpi_mutex_t *mutex) {
	DWORD self = GetCurrentThreadId();

	while (mutex->lock_count != 0
			&& self != mutex->os_thread) {
		unlock_mutex(mutex->os_mutex);
		wait_for_event(mutex->os_cond_lock);
		lock_mutex(mutex->os_mutex);
	}
	mutex->os_thread = self;
	mutex->lock_count++;
}
Ejemplo n.º 27
0
/*
 * main body of the program
 */
int
main(int	argc,
     char *	argv[])
{
  struct rtnl_handle	rth;
  int opt;

  /* Check command line options */
  while((opt = getopt_long(argc, argv, "hv", long_opts, NULL)) > 0)
    {
      switch(opt)
	{
	case 'h':
	  iw_usage(0);
	  break;

	case 'v':
	  return(iw_print_version_info("iwevent"));
	  break;

	default:
	  iw_usage(1);
	  break;
	}
    }
  if(optind < argc)
    {
      fputs("Too many arguments.\n", stderr);
      iw_usage(1);
    }

  /* Open netlink channel */
  if(rtnl_open(&rth, RTMGRP_LINK) < 0)
    {
      perror("Can't initialize rtnetlink socket");
      return(1);
    }

#if WIRELESS_EXT > 13
  fprintf(stderr, "Waiting for Wireless Events...\n");
#else	/* WIRELESS_EXT > 13 */
  fprintf(stderr, "Unsupported in Wireless Extensions <= 14 :-(\n");
  return(-1);
#endif	/* WIRELESS_EXT > 13 */

  /* Do what we have to do */
  wait_for_event(&rth);

  /* Cleanup - only if you are pedantic */
  rtnl_close(&rth);

  return(0);
}
Ejemplo n.º 28
0
extern void native_unmake_thread(struct c_state *c_state)
{
  DIAGNOSTIC(2,"unmaking native thread",0,0);
  c_state->eip = (word)native_thread_exit;
  set_event(c_state->native.event);
  DIAGNOSTIC(3,"set event on thread to unmake, waiting on thread",0,0);
  wait_for_event(c_state->native.thread);
  DIAGNOSTIC(3,"unmade thread signalled, closing handles",0,0);
  close_handle(c_state->native.thread);
  close_handle(c_state->native.event);
  DIAGNOSTIC(3,"closed handles; native thread is history",0,0);
}
Ejemplo n.º 29
0
int ibrdma_transfer(struct transfer_info tfi, int num_tfi) {
  struct addrinfo *addr;
  struct rdma_cm_id *cmid= NULL;
  struct rdma_event_channel *ec = NULL;
  struct rdma_conn_param cm_params;
  int i,j;

  /*Allocation buffer space for reading from local fs to memory*/
  struct transfer_file *ffile = tfi.tfiles;
  int nf = tfi.tfiles;
  char* host = tfi.ib_host;
  char* port; sprintf(port,"%d",tfi.ib_port);
  for (i = 0; i < NUM_FILE_BUF_C; i++) {
    tfi.fbufs[i].fbuf = (char *)malloc(FILE_BUF_SIZE_C);
    tfi.fbufs[i].size = 0;
  }

    TEST_NZ(getaddrinfo(host, port, NULL, &addr));
    TEST_Z(ec = rdma_create_event_channel());
    TEST_NZ(rdma_create_id(ec, &cmid, NULL, RDMA_PS_TCP));
    TEST_NZ(rdma_resolve_addr(cmid, NULL, addr->ai_addr, TIMEOUT_IN_MS));
    TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_ADDR_RESOLVED));
    freeaddrinfo(addr);
    build_connection(cmid);
    TEST_NZ(rdma_resolve_route(cmid, TIMEOUT_IN_MS));
    TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_ROUTE_RESOLVED));
    build_params(&cm_params);
    TEST_NZ(rdma_connect(cmid, &cm_params));
    TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_ESTABLISHED));
    on_connect(cmid->context);
    
    TEST_NZ(wait_for_event(ec, RDMA_CM_EVENT_DISCONNECTED));
    rdma_destroy_id(&cmid);
    rdma_destroy_event_channel(&ec);


  return 0;
}
Ejemplo n.º 30
0
/*
 * i2c_probe: Use write access. Allows to identify addresses that are
 *            write-only (like the config register of dual-port EEPROMs)
 */
static int omap24_i2c_probe(struct i2c_adapter *adap, uchar chip)
{
	struct i2c *i2c_base = omap24_get_base(adap);
	u16 status;
	int res = 1; /* default = fail */

	if (chip == readw(&i2c_base->oa))
		return res;

	/* Wait until bus is free */
	if (wait_for_bb(adap))
		return res;

	/* No data transfer, slave addr only */
	writew(chip, &i2c_base->sa);
	/* Stop bit needed here */
	writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_TRX |
	       I2C_CON_STP, &i2c_base->con);

	status = wait_for_event(adap);

	if ((status & ~I2C_STAT_XRDY) == 0 || (status & I2C_STAT_AL)) {
		/*
		 * With current high-level command implementation, notifying
		 * the user shall flood the console with 127 messages. If
		 * silent exit is desired upon unconfigured bus, remove the
		 * following 'if' section:
		 */
		if (status == I2C_STAT_XRDY)
			printf("i2c_probe: pads on bus %d probably not configured (status=0x%x)\n",
			       adap->hwadapnr, status);

		goto pr_exit;
	}

	/* Check for ACK (!NAK) */
	if (!(status & I2C_STAT_NACK)) {
		res = 0;				/* Device found */
		udelay(adap->waitdelay);/* Required by AM335X in SPL */
		/* Abort transfer (force idle state) */
		writew(I2C_CON_MST | I2C_CON_TRX, &i2c_base->con); /* Reset */
		udelay(1000);
		writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_TRX |
		       I2C_CON_STP, &i2c_base->con);		/* STP */
	}
pr_exit:
	flush_fifo(adap);
	writew(0xFFFF, &i2c_base->stat);
	return res;
}