static int
test_port_stats_multipart(void)
{
    int i;
    struct ind_core_port *port_handles[OFSTATEMANAGER_CONFIG_MAX_PORTS];

    for (i = 0; i < OFSTATEMANAGER_CONFIG_MAX_PORTS; i++) {
        indigo_core_port_register(i, &port_handles[i]);
    }

    memset(port_counters, 0, sizeof(port_counters));
    of_port_stats_request_t *obj = of_port_stats_request_new(OF_VERSION_1_4);
    of_port_stats_request_port_no_set(obj, OF_PORT_DEST_WILDCARD);
    handle_message(obj);
    do_barrier();

    for (i = 0; i < OFSTATEMANAGER_CONFIG_MAX_PORTS; i++) {
        AIM_TRUE_OR_DIE(port_counters[i].stats == 1);
    }

    for (i = 0; i < OFSTATEMANAGER_CONFIG_MAX_PORTS; i++) {
        indigo_core_port_unregister(port_handles[i]);
    }

    return TEST_PASS;
}
Example #2
0
void Router::handle_client(int sfd) {
    if (clients.find(sfd) == clients.end()) {
        DEBUGMSG("Connecting client FID=%d\n", sfd);
        clients[sfd] = make_shared<Client>(sfd);
    } else if(!clients[sfd]->is_connected()) {
        clients.erase(sfd);
        clients[sfd] = make_shared<Client>(sfd);
    }

    SharedClient client = clients[sfd];
    while (true) {
        SharedMessage msg = client->read();

        if (msg) {
            received_messages_size+=(msg->get_length());
            handle_message(client, msg);
            //if we have received too many messages we should send the ones we currently have
            if(received_messages_size > MAX_RECEIVED_MESSAGES_SIZE) {
                handle_write();
            }
        } else {
            if (!client->is_connected()) {
                clients.erase(sfd);

            }
            return;

        }

    }


}
static int
test_queue_desc_stats_multipart(void)
{
    int i, j;
    struct ind_core_port *port_handles[OFSTATEMANAGER_CONFIG_MAX_PORTS];
    struct ind_core_queue *queue_handles[OFSTATEMANAGER_CONFIG_MAX_PORTS];
    const int qid = 3;

    for (i = 0; i < OFSTATEMANAGER_CONFIG_MAX_PORTS; i++) {
        indigo_core_port_register(i, &port_handles[i]);
        indigo_core_queue_register(i, qid, &queue_handles[i]);
    }

    memset(port_counters, 0, sizeof(port_counters));
    of_queue_desc_stats_request_t *obj = of_queue_desc_stats_request_new(OF_VERSION_1_4);
    of_queue_desc_stats_request_port_no_set(obj, OF_PORT_DEST_WILDCARD);
    of_queue_desc_stats_request_queue_id_set(obj, OF_QUEUE_ALL);
    handle_message(obj);
    do_barrier();

    for (i = 0; i < OFSTATEMANAGER_CONFIG_MAX_PORTS; i++) {
        for (j = 0; j < QUEUES_PER_PORT; j++) {
            AIM_TRUE_OR_DIE(port_counters[i].queue_desc_stats[j] ==
                            (j == qid)? 1: 0);
        }
    }

    for (i = 0; i < OFSTATEMANAGER_CONFIG_MAX_PORTS; i++) {
        indigo_core_queue_unregister(queue_handles[i]);
        indigo_core_port_unregister(port_handles[i]);
    }

    return TEST_PASS;
}
Example #4
0
/* Inspect the receive buffer and process any complete messages it contains */
void process_incoming()
{
    int start = 0;

    /* Keep looping until we find an incomplete message, or no more data after
       a complete message */
    while (HEADER_SIZE <= recvbuf.size-start) {
        int size = *(int*)&recvbuf.data[start];
        int tag = *(int*)&recvbuf.data[start+sizeof(int)];

        if (HEADER_SIZE+size > recvbuf.size-start)
            break; /* incomplete message */

        handle_message(tag,size,recvbuf.data+start+HEADER_SIZE);
        start += HEADER_SIZE+size;
    }

    /* If we've consumed any of the data in the buffer, then remove that
       from the front. The remaining data, if any, will be an incomplete
       message. */
    if (0 < start) {
        memmove(&recvbuf.data[0],&recvbuf.data[start],recvbuf.size-start);
        recvbuf.size -= start;
    }
}
Example #5
0
static bool request_handler(const struct sip_msg *msg, void *arg)
{
	struct message *message = arg;
	struct ua *ua;
	struct le *le = message->lsnrl.head;
	bool hdld = false;

	if (pl_strcmp(&msg->met, "MESSAGE"))
		return false;

	ua = uag_find(&msg->uri.user);
	if (!ua) {
		(void)sip_treply(NULL, uag_sip(), msg, 404, "Not Found");
		return true;
	}

	while (le) {
		struct message_lsnr *lsnr = le->data;

		le = le->next;

		handle_message(lsnr, ua, msg);

		hdld = true;
	}

	return hdld;
}
Example #6
0
static DBusMessage *agent_report_peer_error(DBusConnection *connection,
					DBusMessage *message, void *user_data)
{
	struct agent_data *request = user_data;
	char *path, *peer, *error;
	DBusMessageIter iter;

	if (handle_message(message, request,
				agent_report_peer_error) == false)
		return NULL;

	dbus_message_iter_init(message, &iter);

	dbus_message_iter_get_basic(&iter, &path);
	peer = strip_path(path);

	dbus_message_iter_next(&iter);
	dbus_message_iter_get_basic(&iter, &error);

	__connmanctl_save_rl();
	fprintf(stdout, "Agent ReportPeerError %s\n", peer);
	fprintf(stdout, "  %s\n", error);
	__connmanctl_redraw_rl();

	request->message = dbus_message_ref(message);
	__connmanctl_agent_mode("Retry (yes/no)? ",
				report_error_return, request);
	return NULL;
}
Example #7
0
static DBusMessage *agent_report_error(DBusConnection *connection,
		DBusMessage *message, void *user_data)
{
	struct agent_data *request = user_data;
	DBusMessageIter iter;
	char *path, *service, *error;

	if (handle_message(message, request, agent_report_error) == false)
		return NULL;

	dbus_message_iter_init(message, &iter);

	dbus_message_iter_get_basic(&iter, &path);
	service = strip_path(path);

	dbus_message_iter_next(&iter);
	dbus_message_iter_get_basic(&iter, &error);

	__connmanctl_save_rl();
	if (strcmp(request->interface, AGENT_INTERFACE) == 0)
		fprintf(stdout, "Agent ReportError %s\n", service);
	else
		fprintf(stdout, "VPN Agent ReportError %s\n", service);
	fprintf(stdout, "  %s\n", error);
	__connmanctl_redraw_rl();

	request->message = dbus_message_ref(message);
	__connmanctl_agent_mode("Retry (yes/no)? ", report_error_return,
			request);

	return NULL;
}
Example #8
0
static DBusMessage *agent_request_browser(DBusConnection *connection,
		DBusMessage *message, void *user_data)
{
	struct agent_data *request = user_data;
	DBusMessageIter iter;
	char *service, *url;

	if (handle_message(message, request, agent_request_browser) == false)
		return NULL;

	dbus_message_iter_init(message, &iter);

	dbus_message_iter_get_basic(&iter, &service);
	dbus_message_iter_next(&iter);
	dbus_message_iter_get_basic(&iter, &url);

	__connmanctl_save_rl();
	fprintf(stdout, "Agent RequestBrowser %s\n", strip_path(service));
	fprintf(stdout, "  %s\n", url);
	__connmanctl_redraw_rl();

	request->message = dbus_message_ref(message);
	__connmanctl_agent_mode("Connected (yes/no)? ",
			request_browser_return, request);

	return NULL;
}
Example #9
0
int
UBX::receive(unsigned timeout)
{
	/* poll descriptor */
	pollfd fds[1];
	fds[0].fd = _fd;
	fds[0].events = POLLIN;

	uint8_t buf[128];

	/* timeout additional to poll */
	uint64_t time_started = hrt_absolute_time();

	ssize_t count = 0;

	bool handled = false;

	while (true) {

		/* poll for new data, wait for only UBX_PACKET_TIMEOUT (2ms) if something already received */
		int ret = poll(fds, sizeof(fds) / sizeof(fds[0]), handled ? UBX_PACKET_TIMEOUT : timeout);

		if (ret < 0) {
			/* something went wrong when polling */
			return -1;

		} else if (ret == 0) {
			/* return success after short delay after receiving a packet or timeout after long delay */
			return handled ? 1 : -1;

		} else if (ret > 0) {
			/* if we have new data from GPS, go handle it */
			if (fds[0].revents & POLLIN) {
				/*
				 * We are here because poll says there is some data, so this
				 * won't block even on a blocking device. But don't read immediately
				 * by 1-2 bytes, wait for some more data to save expensive read() calls.
				 * If more bytes are available, we'll go back to poll() again.
				 */
				usleep(UBX_WAIT_BEFORE_READ * 1000);
				count = read(_fd, buf, sizeof(buf));

				/* pass received bytes to the packet decoder */
				for (int i = 0; i < count; i++) {
					if (parse_char(buf[i]) > 0) {
						/* return to configure during configuration or to the gps driver during normal work
						 * if a packet has arrived */
						if (handle_message() > 0)
							handled = true;
					}
				}
			}
		}

		/* abort after timeout if no useful packets received */
		if (time_started + timeout * 1000 < hrt_absolute_time()) {
			return -1;
		}
	}
}
Example #10
0
int callback(int message, void* message_data, void* user_data)
{
  YR_MODULE_IMPORT* mi;
  MODULE_DATA* module_data;

  switch(message)
  {
    case CALLBACK_MSG_RULE_MATCHING:
    case CALLBACK_MSG_RULE_NOT_MATCHING:
      return handle_message(message, (YR_RULE*) message_data, user_data);

    case CALLBACK_MSG_IMPORT_MODULE:
      mi = (YR_MODULE_IMPORT*) message_data;

      module_data = modules_data_list;

      while (module_data != NULL)
      {
        if (strcmp(module_data->module_name, mi->module_name) == 0)
        {
          mi->module_data = module_data->module_data;
          mi->module_data_size = module_data->module_data_size;
          break;
        }

        module_data = module_data->next;
      }

      return CALLBACK_CONTINUE;
  }

  return CALLBACK_ERROR;
}
Example #11
0
int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
	int32 result;
	if(!findex || lua_isnil(current_state, findex))
		return TRUE;
	no_action++;
	call_depth++;
	lua_pushvalue(current_state, findex);
	interpreter::card2value(current_state, pcard);
	for(int32 i = 0; i < extraargs; ++i)
		lua_pushvalue(current_state, (int32)(-extraargs - 2));
	if (lua_pcall(current_state, 1 + extraargs, 1, 0)) {
		interpreter::strcpy(pduel->strbuffer, lua_tostring(current_state, -1));
		handle_message(pduel, 1);
		lua_pop(current_state, 1);
		no_action--;
		call_depth--;
		if(call_depth == 0) {
			pduel->release_script_group();
			pduel->restore_assumes();
		}
		return OPERATION_FAIL;
	}
	result = lua_toboolean(current_state, -1);
	lua_pop(current_state, 1);
	no_action--;
	call_depth--;
	if(call_depth == 0) {
		pduel->release_script_group();
		pduel->restore_assumes();
	}
	return result;
}
Example #12
0
int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraargs) {
	int32 result;
	if(!findex || lua_isnil(current_state, findex))
		return 0;
	no_action++;
	call_depth++;
	lua_pushvalue(current_state, findex);
	interpreter::card2value(current_state, pcard);
	for(int32 i = 0; i < extraargs; ++i)
		lua_pushvalue(current_state, (int32)(-extraargs - 2));
	if (lua_pcall(current_state, 1 + extraargs, 1, 0)) {
		sprintf(pduel->strbuffer, lua_tostring(current_state, -1));
		handle_message(pduel, 1);
		lua_pop(current_state, 1);
		no_action--;
		call_depth--;
		if(call_depth == 0)
			pduel->release_script_group();
		return OPERATION_FAIL;
	}
	result = lua_tointeger(current_state, -1);
	lua_pop(current_state, 1);
	no_action--;
	call_depth--;
	if(call_depth == 0)
		pduel->release_script_group();
	return result;
}
Example #13
0
int
UBX::receive(unsigned timeout)
{
	/* poll descriptor */
	pollfd fds[1];
	fds[0].fd = _fd;
	fds[0].events = POLLIN;

	uint8_t buf[32];

	/* timeout additional to poll */
	uint64_t time_started = hrt_absolute_time();

	int j = 0;
	ssize_t count = 0;

	while (true) {

		/* pass received bytes to the packet decoder */
		while (j < count) {
			if (parse_char(buf[j]) > 0) {
				/* return to configure during configuration or to the gps driver during normal work
				 * if a packet has arrived */
				 if (handle_message() > 0)
					return 1;
			}
			/* in case we keep trying but only get crap from GPS */
			if (time_started + timeout*1000 < hrt_absolute_time() ) {
				return -1;
			}
			j++;
		}

		/* everything is read */
		j = count = 0;

		/* then poll for new data */
		int ret = ::poll(fds, sizeof(fds) / sizeof(fds[0]), timeout);

		if (ret < 0) {
			/* something went wrong when polling */
			return -1;

		} else if (ret == 0) {
			/* Timeout */
			return -1;

		} else if (ret > 0) {
			/* if we have new data from GPS, go handle it */
			if (fds[0].revents & POLLIN) {
				/*
				 * We are here because poll says there is some data, so this
				 * won't block even on a blocking device.  If more bytes are
				 * available, we'll go back to poll() again...
				 */
				count = ::read(_fd, buf, sizeof(buf));
			}
		}
	}
}
Example #14
0
static void handle_msg_element(uint8_t msg_type, stlv_packet pack, element_handle handle)
{
    element_handle begin = get_first_sub_element(pack, handle);
    char filter[2] = { SUB_TYPE_MESSAGE_IDENTITY, SUB_TYPE_MESSAGE_MESSAGE, };
    element_handle sub_handles[2] = {0};
    int sub_element_count = filter_elements(pack, handle, begin, filter, 2, sub_handles);
    if (sub_element_count != 0x03)
    {
        log_info("Cannot find expected sub-elements: %c, %c\n", filter[0], filter[1]);
        return;
    }

    int identity_len = get_element_data_size(pack, sub_handles[0], NULL, 0);
    unsigned char* identity_data = get_element_data_buffer(pack, sub_handles[0], NULL, 0);

    int message_len = get_element_data_size(pack, sub_handles[1], NULL, 0);
    unsigned char* message_data = get_element_data_buffer(pack, sub_handles[1], NULL, 0);

    identity_data[identity_len] = '\0';
    message_data[message_len] = '\0';
    log_info("From: %s\n", identity_data);
    log_info("Message: %s\n", message_data);
    handle_message(msg_type, (char*)identity_data, (char*)message_data);

}
Example #15
0
// make one pass through msgs_from_host with handled == 0
// return true if there were any
//
bool do_message_scan() {
    DB_MSG_FROM_HOST mfh;
    char buf[256];
    bool found=false;
    int retval;

    sprintf(buf, "where handled=0");
    while (1) {
        retval = mfh.enumerate(buf);
        if (retval) {
            if (retval != ERR_DB_NOT_FOUND) {
                log_messages.printf(MSG_DEBUG,
                    "DB connection lost, exiting\n"
                );
                exit(0);
            }
            break;
        }
        retval = handle_message(mfh);
        if (!retval) {
            mfh.handled = true;
            mfh.update();
        }
        found = true;
    }
    return found;
}
/**
 * Receive data from UART.
 */
static void *
receive_thread(void *arg)
{
  int uart_fd = *((int*)arg);

  const int timeout = 1000;
  uint8_t ch;

  mavlink_message_t msg;

  prctl(PR_SET_NAME, "mavlink offb mod rcv", getpid());

  while (!thread_should_exit)
  {

    struct pollfd fds[] = { {.fd = uart_fd, .events = POLLIN}};

    if (poll(fds, 1, timeout) > 0)
    {
      /* non-blocking read until buffer is empty */
      int nread = 0;

      do
      {
        nread = read(uart_fd, &ch, 1);

        if (mavlink_parse_char(chan, ch, &msg, &status))
        { //parse the char
          /* handle generic messages and commands */
          handle_message(&msg);
        }
      } while (nread > 0);
    }
  }
Example #17
0
static DBusHandlerResult filter (DBusConnection *conn, DBusMessage *msg,
        void *arg) {
    
    (void) conn;
    (void) arg;

    struct ep_list_head_s *head = &cb_list;
    struct ep_list_node_s *node = NULL;
    struct cb_data *data = NULL;

    /* printf("libep: policy event received\n"); */

    if (ep_list_empty(head))
        goto end;

    node = head->first;
    
    while (node) {
        data = node->data;
        if (dbus_message_is_signal(msg, POLICY_DBUS_INTERFACE, data->signal)) {
            handle_message(msg, data);
        }
        node = node->next;
    }

end:
    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
Example #18
0
/**
 * Receive data from UART.
 */
static void *
receive_thread(void *arg)
{
	int uart_fd = *((int *)arg);

	const int timeout = 1000;
	uint8_t buf[32];

	mavlink_message_t msg;

	prctl(PR_SET_NAME, "mavlink uart rcv", getpid());

	while (!thread_should_exit) {

		struct pollfd fds[] = { { .fd = uart_fd, .events = POLLIN } };

		if (poll(fds, 1, timeout) > 0) {
			/* non-blocking read. read may return negative values */
			ssize_t nread = read(uart_fd, buf, sizeof(buf));

			/* if read failed, this loop won't execute */
			for (ssize_t i = 0; i < nread; i++) {
				if (mavlink_parse_char(chan, buf[i], &msg, &status)) {
					/* handle generic messages and commands */
					handle_message(&msg);

					/* Handle packet with waypoint component */
					mavlink_wpm_message_handler(&msg, &global_pos, &local_pos);

					/* Handle packet with parameter component */
					mavlink_pm_message_handler(MAVLINK_COMM_0, &msg);
				}
			}
		}
	}
Example #19
0
 /**
  * Handle a new order with MPID.
  *
  * @param recvts the timestamp when the message was received
  * @param msgcnt the number of messages received before this message
  * @param msgoffset the number of bytes received before this message
  * @param msg the message describing a new order
  */
 void handle_message(
     time_point recvts, long msgcnt, std::size_t msgoffset,
     add_order_mpid_message const& msg) {
   // ... delegate to the handler for add_order_message (without mpid) ...
   handle_message(
       recvts, msgcnt, msgoffset, static_cast<add_order_message const&>(msg));
 }
Example #20
0
static DBusMessage *agent_release(DBusConnection *connection,
		DBusMessage *message, void *user_data)
{
	struct agent_data *request = user_data;

	if (handle_message(message, request, agent_release) == false)
		return NULL;

	g_dbus_unregister_interface(connection, agent_path(),
			request->interface);
	request->registered = false;

	pending_message_remove(request);

	if (strcmp(request->interface, AGENT_INTERFACE) == 0)
		pending_command_complete("Agent unregistered by ConnMan\n");
	else
		pending_command_complete("VPN Agent unregistered by ConnMan "
				"VPNd\n");

	if (__connmanctl_is_interactive() == false)
		__connmanctl_quit();

	return dbus_message_new_method_return(message);
}
static void
handle_current_sync (GstDiscoverer * dc)
{
  GTimer *timer;
  gdouble deadline = ((gdouble) dc->priv->timeout) / GST_SECOND;
  GstMessage *msg;
  gboolean done = FALSE;

  timer = g_timer_new ();
  g_timer_start (timer);

  do {
    /* poll bus with timeout */
    /* FIXME : make the timeout more fine-tuned */
    if ((msg = gst_bus_timed_pop (dc->priv->bus, GST_SECOND / 2))) {
      done = handle_message (dc, msg);
      gst_message_unref (msg);
    }

  } while (!done && (g_timer_elapsed (timer, NULL) < deadline));

  /* return result */
  if (!done) {
    GST_DEBUG ("we timed out! Setting result to TIMEOUT");
    dc->priv->current_info->result = GST_DISCOVERER_TIMEOUT;
  }

  GST_DEBUG ("Done");

  g_timer_stop (timer);
  g_timer_destroy (timer);
}
Example #22
0
File: exec.c Project: Vuldo/42sh
void    dad(t_sh *sh, pid_t pid)
{
  int   status;
  char	buff[5];

  my_memset(buff, 0, 5);
  if (sh->actual->piper_read != NULL && sh->actual->fd[0] != 0)
    {
      close(sh->actual->piper_read->pipe[0]);
      close(sh->actual->piper_read->pipe[1]);
    }
  if (sh->actual->piper_write != NULL)
    waitpid(pid, &status, WNOHANG);
  else
    waitpid(pid, &status, 0);
  if (sh->actual->fd[0] != 0)
    close(sh->actual->fd[0]);
  if (sh->actual->fd[1] != 1)
    close(sh->actual->fd[1]);
  if (WEXITSTATUS(status) == 0)
      return_exec_success(sh);
  sprintf(buff, "%d", WEXITSTATUS(status));
  my_setenv(&sh->env, "?", buff);
  handle_message(status);
  freetab(sh->av);
}
Example #23
0
/* No form window is open */
void bg_event_loop()
{
	int x,y,kstate,key,clicks,event,state;
	int pipe[8];


#ifdef DEBUG
	form_alert(1,"[1][ACC bg][Ok]");
#endif
	do {
		event = evnt_multi( MU_MESAG | MU_TIMER,
							2, 0x1, 1,
							0, 0, 0, 0, 0,
							0, 0, 0, 0, 0,
							pipe,
							time_slice, 0,
							&x, &y, &state, &kstate, &key, &clicks );

		if (event & MU_TIMER)
			if (replay)
			{
				if(first_init)
					checkhang();
				load(1);
				update_time();
			}

		if (event & MU_MESAG)
		{
			handle_message(pipe); /* no window to handle */
		}

			
	} while ((fgbg==BG) && !closed_acc);
}
Example #24
0
bool ForeignMenuConnection::read_msgs()
{
    uint8_t *pos = _read_buf;
    size_t nread = _read_pos - _read_buf;
    int32_t size;

    ASSERT(_handler);
    ASSERT(_opaque != NamedPipe::INVALID_CONNECTION);
    size = NamedPipe::read(_opaque, (uint8_t*)_read_pos, sizeof(_read_buf) - nread);
    if (size == 0) {
        return false;
    } else if (size < 0) {
        LOG_ERROR("Error reading from named pipe %d", size);
        _parent.remove_connection(_opaque);
        return false;
    }
    nread += size;
    while (nread > 0) {
        if (!_initialized && nread >= sizeof(FrgMenuInitHeader)) {
            FrgMenuInitHeader *init = (FrgMenuInitHeader *)pos;
            if (init->magic != FOREIGN_MENU_MAGIC || init->version != FOREIGN_MENU_VERSION) {
                LOG_ERROR("Bad foreign menu init, magic=0x%x version=%u", init->magic,
                          init->version);
                _parent.remove_connection(_opaque);
                return false;
            }
            if (nread < init->size) {
                break;
            }
            if (!handle_init((FrgMenuInit*)init)) {
                _parent.remove_connection(_opaque);
                return false;
            }
            nread -= init->size;
            pos += init->size;
            _initialized = true;
        }
        if (!_initialized || nread < sizeof(FrgMenuMsg)) {
            break;
        }
        FrgMenuMsg *hdr = (FrgMenuMsg *)pos;
        if (hdr->size < sizeof(FrgMenuMsg)) {
            LOG_ERROR("Bad foreign menu message, size=%u", hdr->size);
            _parent.remove_connection(_opaque);
            return false;
        }
        if (nread < hdr->size) {
            break;
        }
        handle_message(hdr);
        nread -= hdr->size;
        pos += hdr->size;
    }
    if (nread > 0 && pos != _read_buf) {
        memmove(_read_buf, pos, nread);
    }
    _read_pos = _read_buf + nread;
    return true;
}
Example #25
0
int main(int argc, char *argv[]) { /* {{{ */
    char buf[MAXBUF];

    char *plain;
    unsigned char *ubuf = (unsigned char *)buf;

    struct sockaddr_in server, from;

    EVP_CIPHER_CTX ctx;

    int          sock, n;
    unsigned int fromlen = sizeof from;

    unsigned char *key_data = (unsigned char*)"passphrase";
    int key_data_len = strlen("passphrase");
    int len = 1024;

    if(key_init(key_data, key_data_len, &ctx)){
        printf("Key creation failed\n");
        exit(EXIT_FAILURE);
    }

    parse_options(argc, argv);

    if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
        perror("error opening socket");
        exit(EXIT_FAILURE);
    }

    memset(&server, '\0', sizeof server);

    server.sin_family      = AF_INET;
    server.sin_port        = htons(portno);
    server.sin_addr.s_addr = INADDR_ANY;

    if (bind(sock, (struct sockaddr *)&server, sizeof server) < 0) {
        perror("error binding to socket");
        exit(EXIT_FAILURE);
    }

    while (1) {
        while ((n = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen)) < 0 && errno == EINTR)
            ;

        if (n < 0) {
            perror("error receiving from socket");
            exit(EXIT_FAILURE);
        }

        len=strlen(buf)+1;
        plain=(char *)decrypt(&ctx,ubuf,&len);

        handle_message(plain);
    }
    EVP_CIPHER_CTX_cleanup(&ctx);
    free(plain);
    free(ubuf);
    free(key_data);
}
Example #26
0
 /**
  * Handle an order execution with a different price than the order's
  *
  * @param recvts the timestamp when the message was received
  * @param msgcnt the number of messages received before this message
  * @param msgoffset the number of bytes received before this message
  * @param msg the message describing the execution
  */
 void handle_message(
     time_point recvts, long msgcnt, std::size_t msgoffset,
     order_executed_price_message const& msg) {
   // ... delegate on the handler for add_order_message (without price) ...
   handle_message(
       recvts, msgcnt, msgoffset,
       static_cast<order_executed_message const&>(msg));
 }
static gboolean
on_message (GstBus * bus, GstMessage * msg, gpointer userdata)
{
  InsanityGstPipelineTest *ptest = INSANITY_GST_PIPELINE_TEST (userdata);
  if (handle_message (ptest, msg))
    g_main_loop_quit (ptest->priv->loop);
  return TRUE;
}
Example #28
0
void read_message(char address) {
	char header = spi_read(address);
	char size = spi_read(address);
	char data[size];
	for (int i = 0; i < size; i++) {
		data[i] = spi_read(address);
	}
	handle_message(header, size, (char *)&data);
}
Example #29
0
	void handle_radio(const mavlink_message_t *msg, uint8_t sysid, uint8_t compid) {
		if (has_radio_status)
			return;

		// actually the same data, but from earlier modems
		mavlink_radio_t rst;
		mavlink_msg_radio_decode(msg, &rst);
		handle_message(rst, sysid, compid);
	}
Example #30
0
int32 scriptlib::debug_message(lua_State *L) {
	duel* pduel = interpreter::get_duel_info(L);
	lua_getglobal(L, "tostring");
	lua_pushvalue(L, -2);
	lua_pcall(L, 1, 1, 0);
	sprintf(pduel->strbuffer, "%s", lua_tostring(L, -1));
	handle_message(pduel, 2);
	return 0;
}