Ejemplo n.º 1
0
int app::run(){
	
	while(m_brun){
		
		void* data = NULL;
		if(m_ring_buf.pop(data) == -1){
			continue;
		}
		
		app_hd * msg = (app_hd*)data;
		if(msg->type == tcp_type){
			switch(msg->event){
				case ev_sys_recv:
					on_recv(msg->u.tcp.n, msg->content, msg->length);
					break;
					
				case ev_sys_close:
					on_close(msg->u.tcp.n, *((int*)msg->content));
					delete msg->u.tcp.n;
					break;
					
				case ev_sys_accept:
					on_accept(msg->u.tcp.n);
					break;
					
				case ev_sys_connect_ok:
					on_connect(msg->u.tcp.n);
					break;
					
				case ev_sys_connect_fail:
					on_connect(msg->u.tcp.n);
					delete msg->u.tcp.n;
				break;
				
			}
		}
		else if(msg->type == timer_type){
			on_timer(msg->event, msg->u.timer.interval, msg->u.timer.ptr);
		}
		else if(msg->type == app_type){
			on_app(msg->event, msg->content, msg->length);
		}
		else{
			error_log("msg from unknown app_name(%s)\n", m_name);
		}
		free(msg);
	}
	return 0;
}
Ejemplo n.º 2
0
int on_connection(struct rdma_cm_id *id)
{
  printf("Established\n");
  on_connect(id->context);

  return 0;
}
Ejemplo n.º 3
0
void ble_hrs_on_ble_evt(uint16_t * p_peripheral_conn_handle, ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt)
{
    uint16_t peripheral_conn_handle  = * p_peripheral_conn_handle; //todo;
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            if(p_ble_evt->evt.gap_evt.params.connected.role == BLE_GAP_ROLE_PERIPH) //If this side is BLE_GAP_ROLE_PERIPH then BLE_GAP_EVT_CONNECTED comes from peer central
            {
            on_connect(p_hrs, p_ble_evt);
            }
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            if(p_ble_evt->evt.gap_evt.conn_handle == peripheral_conn_handle)
            {
                on_disconnect(p_hrs, p_ble_evt);
            }
            break;

        case BLE_GATTS_EVT_WRITE:
            on_write(p_hrs, p_ble_evt);
            break;
        
         case BLE_GATTC_EVT_HVX:
            on_peer_peripheral_hvx(p_hrs, p_ble_evt);
        
            

        default:
            // No implementation needed.
            break;
    }
}
Ejemplo n.º 4
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.º 5
0
void
IghtConnectionState::handle_event(bufferevent *bev, short what, void *opaque)
{
	auto self = (IghtConnectionState *) opaque;

	(void) bev;  // Suppress warning about unused variable

	if (self->connecting && self->closing) {
		delete (self);
		return;
	}

	if (what & BEV_EVENT_CONNECTED) {
		self->connecting = 0;
		self->on_connect();
		return;
	}

	if (what & BEV_EVENT_EOF) {
		self->on_error(IghtError(0));
		return;
	}

	if (self->connecting) {
		ight_info("connection::handle_event - try connect next");
		self->connect_next();
		return;
	}

	// TODO: also handle the timeout

	self->on_error(IghtError(-1));
}
Ejemplo n.º 6
0
void ble_nus_on_ble_evt(ble_nus_t * p_nus, ble_evt_t * p_ble_evt)
{
	

    if ((p_nus == NULL) || (p_ble_evt == NULL))
    {
        return;
    }

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_nus, p_ble_evt);

            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_nus, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:    // host에서 data를 write 할때 들어옴.
            on_write(p_nus, p_ble_evt);
		            break;

        default:
            // No implementation needed.
            break;
    }
}
Ejemplo n.º 7
0
void udp_server::poll (uint16_t milliseconds)
{
    ENetEvent ev;
    auto result (enet_host_service(sv_, &ev, milliseconds));

    if (result < 0)
        throw std::runtime_error((format("network error %1%") % -result).str());

    switch (ev.type)
    {
        case ENET_EVENT_TYPE_CONNECT:
            on_connect(ev.peer);
            break;

        case ENET_EVENT_TYPE_RECEIVE:
            on_receive(ev.peer, packet(ev.packet->data, ev.packet->dataLength));
            enet_packet_destroy(ev.packet);
            break;

        case ENET_EVENT_TYPE_DISCONNECT:
            on_disconnect(ev.peer);
            break;

        case ENET_EVENT_TYPE_NONE:
            break;
    }
}
Ejemplo n.º 8
0
void ble_blinkys_on_ble_evt(ble_blinkys_t * p_blinkys, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_blinkys, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_blinkys, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
        	{
        		ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

        		if ((p_evt_write->handle == p_blinkys->blinky_char_handles.value_handle) &&
        	       (p_evt_write->len > 0) &&
        	       (p_blinkys->write_handler != NULL))
        		{
        			p_blinkys->write_handler(p_blinkys, p_evt_write->data, p_evt_write->len);
        		}
        	}
            break;

        default:
            break;
    }
}
Ejemplo n.º 9
0
void ble_lc_on_ble_event(ble_lc_t * p_lc, ble_evt_t * p_ble_evt)
{
	if ((p_lc == NULL) || (p_ble_evt == NULL))
  {
     return;
  }
	
	switch (p_ble_evt->header.evt_id)
	{
		case BLE_GAP_EVT_CONNECTED:
			on_connect(p_lc, p_ble_evt);
			break;
		
		case BLE_GAP_EVT_DISCONNECTED:
			on_disconnect(p_lc, p_ble_evt);
			break;
		
		case BLE_GATTS_EVT_WRITE:
			on_write(p_lc, p_ble_evt);
			break;
		
		case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
			on_read(p_lc, p_ble_evt);
			break;
		
		default:
			// Nothing needed
			break;		
	}
}
Ejemplo n.º 10
0
static void cb_connection(uv_stream_t *stream, int status)
{
	ws_server_t *ptr = (ws_server_t*)stream->data;

	ws_connect_t *pConnect = NULL;

    ptr->cb.cb_malloc(pConnect, ptr->cb.obj_malloc);
    
    if (NULL == pConnect)
    {
        printf("->strerror:malloc connect error,(%s,%d)\n", __FILE__, __LINE__);
        return;
    }
    
	if(0 == uv_accept((uv_stream_t *)(&ptr->server), (uv_stream_t*)(&pConnect->connect)))
	{
        pConnect->state = WS_CONNECTING;
		on_connect(pConnect);
	}
    else
    {
        if (NULL != ptr->cb.cb_connection)
        {
            ptr->cb.cb_connection(pConnect, ptr->cb.obj_connection, WS_ERROR_BAD);
        }
        else
        {
            printf("->strerror:accept error,(%s,%d)\n", __FILE__, __LINE__);
        }
	}
}
Ejemplo n.º 11
0
Archivo: main.c Proyecto: pzl/piwm
int main (int argc, char **argv) {
	(void) argc;
	(void) argv;

	// network
	int sock;
	int client;

	//GRAPHICS VARS
	Display screen;

	screen = setup_graphics();
	sock = setup_socket();


	// ----------------------

	// Network update vars and setup
	struct sockaddr_storage remote_addr;
	socklen_t addr_size = sizeof(remote_addr);


	while ( (client = accept(sock, (struct sockaddr *)&remote_addr, &addr_size)) > 0){
		on_connect(client, remote_addr, screen);
		//@todo: method to break here, or catch signals
		//and end up in code below, closing socket and cleaning up GPU
		//would need to close threads and clients
	}

	close(sock);
	vc_dispmanx_display_close(screen.display);


	return 0;
}
Ejemplo n.º 12
0
void
XboxdrvDaemon::connect(ControllerSlotPtr slot, ControllerPtr controller)
{
  log_info("connecting slot to thread");

  try 
  {
    // set the LED status
    if (slot->get_led_status() == -1)
    {
      controller->set_led(static_cast<uint8_t>(2 + (slot->get_id() % 4)));
    }
    else
    {
      controller->set_led(static_cast<uint8_t>(slot->get_led_status()));
    }
  }
  catch(const std::exception& err)
  {
    log_error("failed to set led: " << err.what());
  }
  
  slot->connect(controller);
  on_connect(slot);

  log_info("controller connected: " 
           << controller->get_usbpath() << " "
           << controller->get_usbid() << " "
           << "'" << controller->get_name() << "'");

  log_info("launched Controller for " << controller->get_usbpath()
           << " in slot " << slot->get_id() << ", free slots: " 
           << get_free_slot_count() << "/" << m_controller_slots.size());
}
Ejemplo n.º 13
0
int on_connection(struct rdma_cm_id *id)
{
  on_connect(id->context);
  send_mr(id->context);

  return 0;
}
Ejemplo n.º 14
0
void ble_lmxs_on_ble_evt(ble_lmxs_t * p_lmxs, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_lmxs, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_lmxs, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
        	{
        	    ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
        	    GATMEMHDR *hdr = (GATMEMHDR *)g_GatWriteBuff;
        	    uint8_t *p = (uint8_t*)g_GatWriteBuff;

        		if (p_evt_write->handle == 0 && p_evt_write->op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW)
        		{
        			static char buff[256];
        			int len = 0;
        			while (hdr->Handle == p_lmxs->char_handles.value_handle)
        		    {
        				memcpy(buff + hdr->Offset, hdr->Data, hdr->Len);
        				len += hdr->Len;
        				p += hdr->Len + 6;
        				hdr = (GATMEMHDR*)p;
        		    }
       				p_lmxs->write_handler(p_lmxs, buff, 0, len);//p_evt_write->data);
        			return;
        		}
        		else if ((p_evt_write->handle == p_lmxs->char_handles.value_handle) &&
        	       (p_evt_write->len > 0) && (p_lmxs->write_handler != NULL))
        		{
        			p_lmxs->write_handler(p_lmxs, p_evt_write->data, 0, p_evt_write->len);
        		}
        	}
            break;
        case BLE_EVT_USER_MEM_REQUEST:
        	{
        		uint32_t err_code;
        		ble_user_mem_block_t mblk;
        		memset(&mblk, 0, sizeof(ble_user_mem_block_t));
        		mblk.p_mem = g_GatWriteBuff;
        		mblk.len = sizeof(g_GatWriteBuff);
        		memset(g_GatWriteBuff, 0, sizeof(g_GatWriteBuff));
        		err_code = sd_ble_user_mem_reply(p_lmxs->conn_handle, &mblk);
        		APP_ERROR_CHECK(err_code);
        	}
        	break;
        case BLE_EVT_USER_MEM_RELEASE:
//        	err_code = sd_ble_user_mem_reply(g_EkoCCServ.conn_handle, NULL);
//        	APP_ERROR_CHECK(err_code);
        	break;

        default:
            break;
    }
}
Ejemplo n.º 15
0
void ble_sc_ctrlpt_on_ble_evt(ble_sc_ctrlpt_t * p_sc_ctrlpt, ble_evt_t const * p_ble_evt)
{
    if (p_sc_ctrlpt == NULL || p_ble_evt == NULL)
    {
        return;
    }

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_sc_ctrlpt, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_sc_ctrlpt, p_ble_evt);
            break;

        case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
            on_rw_authorize_request(p_sc_ctrlpt, &p_ble_evt->evt.gatts_evt);
            break;

        case BLE_GATTS_EVT_HVC:
            on_sc_hvc_confirm(p_sc_ctrlpt, p_ble_evt);
            break;

        case BLE_GATTS_EVT_HVN_TX_COMPLETE:
            on_tx_complete(p_sc_ctrlpt);
            break;

        default:
            break;
    }
}
Ejemplo n.º 16
0
void udp_client::poll(unsigned int milliseconds)
{
    ENetEvent ev;
    int result;
    {
        boost::lock_guard<boost::mutex> lock(host_mutex_);
        result = enet_host_service(host_, &ev, milliseconds);
    }

    if (result < 0)
        throw std::runtime_error(
            (format("network error %1%") % -result).str());

    switch (ev.type) {
    case ENET_EVENT_TYPE_CONNECT:
        on_connect();
        break;

    case ENET_EVENT_TYPE_RECEIVE:
        receive(packet(ev.packet->data, ev.packet->dataLength));
        break;

    case ENET_EVENT_TYPE_DISCONNECT:
        on_disconnect();
        break;

    case ENET_EVENT_TYPE_NONE:
        break;
    }

    if (ev.packet != nullptr)
        enet_packet_destroy(ev.packet);
}
Ejemplo n.º 17
0
void ble_hts_on_ble_evt(ble_hts_t * p_hts, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_hts, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_hts, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
            on_write(p_hts, p_ble_evt);
            break;

        case BLE_GATTS_EVT_HVC:
            on_hvc(p_hts, p_ble_evt);
            break;

        default:
            // No implementation needed.
            break;
    }
}
Ejemplo n.º 18
0
void ble_ias_c_on_ble_evt(ble_ias_c_t * p_ias_c, ble_evt_t const * p_ble_evt)
{
    uint32_t err_code = NRF_SUCCESS;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            err_code = on_connect(p_ias_c, p_ble_evt);
            break;

        case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
            err_code = on_srv_disc_resp(p_ias_c, p_ble_evt);
            break;

        case BLE_GATTC_EVT_CHAR_DISC_RSP:
            on_char_disc_resp(p_ias_c, p_ble_evt);
            break;

       case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_ias_c, p_ble_evt);
            break;

        default:
            break;
    }

    if (err_code != NRF_SUCCESS && p_ias_c->error_handler != 0)
    {
        p_ias_c->error_handler(err_code);
    }
}
Ejemplo n.º 19
0
void ble_iqo_on_ble_evt(ble_iqo_t * p_iqo, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_iqo, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_iqo, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
            on_write(p_iqo, p_ble_evt);
            break;

        case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
        	on_rw_authorize_request(p_iqo, p_ble_evt);
        	break;

        default:
            // No implementation needed.
            break;
    }
}
Ejemplo n.º 20
0
void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
            on_write(p_ble_evt);
            break;

        case BLE_GAP_EVT_CONN_PARAM_UPDATE:
            on_conn_params_update(p_ble_evt);
            break;

        default:
            // No implementation needed.
            break;
    }
}
Ejemplo n.º 21
0
void ble_bas_on_ble_evt(ble_bas_t * p_bas, ble_evt_t * p_ble_evt)
{
    if (p_bas == NULL || p_ble_evt == NULL)
    {
        return;
    }

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_bas, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_bas, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
            on_write(p_bas, p_ble_evt);
            break;

        default:
            // No implementation needed.
            break;
    }
}
Ejemplo n.º 22
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.º 23
0
void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
{
    if ((p_dfu == NULL) || (p_ble_evt == NULL))
    {
        return;
    }

    if (p_dfu->evt_handler != NULL)
    {
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_CONNECTED:
                on_connect(p_dfu, p_ble_evt);
                break;

            case BLE_GATTS_EVT_WRITE:
                on_write(p_dfu, p_ble_evt);
                break;

            case BLE_GAP_EVT_DISCONNECTED:
                on_disconnect(p_dfu, p_ble_evt);
                break;

            case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
                on_rw_authorize_req(p_dfu, p_ble_evt);
                break;

            default:
                // No implementation needed.
                break;
        }
    }
}
Ejemplo n.º 24
0
void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
{
    VERIFY_PARAM_NOT_NULL_VOID(p_dfu);
    VERIFY_PARAM_NOT_NULL_VOID(p_ble_evt);

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_dfu, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_dfu, p_ble_evt);
            break;

        case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
            on_rw_authorize_req(p_dfu, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
            on_write(p_dfu, p_ble_evt);
            break;

        default:
            // no implementation
            break;
    }

}
Ejemplo n.º 25
0
static void cb_connect(uv_connect_t* req, int status)
{
	ws_connect_t *ptr = (ws_connect_t*)req->data;

	//print_info();

	on_connect(ptr);
}
Ejemplo n.º 26
0
int client_on_connection(struct rdma_cm_id *id)
{
    on_connect(id->context);
    send_mr(id->context);

    /// if built connection, return 1, and break the while in wait_rdma_event()
    return 1;
}
Ejemplo n.º 27
0
 void node::accept_loop()
 {
    while( !_accept_loop.canceled() )
    {
       auto new_connection = std::make_shared<peer_connection>();
       _server.accept( new_connection->_socket );
       on_connect( new_connection );
    }
 }
Ejemplo n.º 28
0
int on_connection(struct rdma_cm_id *id)
{
  on_connect(id->context);
  time_stamp(1);
  time_stamp(4);
  //send_mr(id->context);
  conn_context = (void*)id->context;
  return 0;
}
Ejemplo n.º 29
0
int app::dispatch(const app_hd * msg){
	
	if(msg->type == tcp_type){
		switch(msg->event){
			case ev_sys_recv:
				on_recv(msg->u.tcp.n, msg->content, msg->length);
				break;
				
			case ev_sys_close:
				on_close(msg->u.tcp.n, *((int*)msg->content));
				delete msg->u.tcp.n;
				break;
				
			case ev_sys_accept:
				on_accept(msg->u.tcp.n);
				break;
				
			case ev_sys_connect_ok:
				on_connect(msg->u.tcp.n);
				break;
				
			case ev_sys_connect_fail:
				on_connect(msg->u.tcp.n);
				delete msg->u.tcp.n;
			break;
			
			case ev_sys_write:
				handle_write(msg->u.tcp.n);
			break;
		}
	}
	else if(msg->type == timer_type){
		on_timer(msg->event, msg->u.timer.interval, msg->u.timer.ptr);
	}
	else if(msg->type == app_type){
		on_app(msg->event, msg->content, msg->length);
	}
	else{
		error_log("msg from unknown app_name(%s)\n", m_name);
	}
	return 0;	
}
Ejemplo n.º 30
0
int mylistener(int port)
{

    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));

    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = inet_addr("127.0.0.1");

    int fd = socket(AF_INET, SOCK_STREAM, 0);
    if (fd < 0)
    {
        printf("socket error!\n");
        return -1;
    }

    set_socket_reuseable(fd);
    int ret = bind(fd, (struct sockaddr*)&addr, sizeof(addr));
    if (ret < 0)
    {
        printf("bind error!\n");
        return -1;
    }

    ret = listen(fd, 10);
    if (ret < 0)
    {
        printf("listen error!\n");
        return -1;
    }

    while (1)
    {
        printf("begin accept\n");
        struct sockaddr_in client_addr;
        socklen_t len = sizeof(client_addr);
        memset(&client_addr, 0, sizeof(client_addr));
        int clientfd = accept(fd, (struct sockaddr*)&client_addr, &len);
        if (clientfd)
        {
            on_connect(clientfd, (struct sockaddr*)&client_addr);
        }
        else
        {
            printf("accept error !\n");
        }
    }



    return 0;
}