Exemple #1
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;		
	}
}
Exemple #2
0
void client_disconnect(void){

    struct rdma_event_channel *ec = s_ctx->ec;
    struct rdma_cm_id *id = s_ctx->id;
    struct rdma_cm_event *event = NULL;

        printf("ready to disconnect\n");
        rdma_disconnect(id);
        printf("send disconnect\n");

while(1){
    if(rdma_get_cm_event(ec, &event) == 0) {
        struct rdma_cm_event event_copy;
        memcpy(&event_copy, event, sizeof(*event));
        rdma_ack_cm_event(event);

        if (event_copy.event == RDMA_CM_EVENT_DISCONNECTED){
            on_disconnect(event_copy.id);
            rdma_destroy_event_channel(ec);
            break;
        }
    }

}

  return;

}
Exemple #3
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;
    }
}
Exemple #4
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;
        }
    }
}
Exemple #5
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;
    }
}
Exemple #6
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;
    }
}
Exemple #7
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;
    }
}
Exemple #8
0
void client_disconnect(void){

    struct rdma_event_channel *ec = s_ctx->ec;
    struct rdma_cm_id *id = s_ctx->id;
    struct rdma_cm_event *event = NULL;
    struct timeval start, end, dt;

        gettimeofday(&start, NULL);
        printf("ready to disconnect\n");
        rdma_disconnect(id);
        printf("send disconnect\n");
        gettimeofday(&end, NULL);
        timersub(&end, &start, &dt); 
        long usec = dt.tv_usec + 1000000 * dt.tv_sec;
        printf("[rdma_disconnect] takes %ld micro_secs.\n", usec);

    while(1){
        if(rdma_get_cm_event(ec, &event) == 0) {
            struct rdma_cm_event event_copy;
            memcpy(&event_copy, event, sizeof(*event));
            rdma_ack_cm_event(event);
    
            if (event_copy.event == RDMA_CM_EVENT_DISCONNECTED){
                on_disconnect(event_copy.id);
                rdma_destroy_event_channel(ec);
                break;
            }
        }
    
    }

  return;

}
Exemple #9
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;
    }
}
Exemple #10
0
    /// 接收线程推进
    void tcp_session::run()
    {
        if (m_notify_connected)
        {
            connect_invoke();
            m_notify_connected = false;
        }

        post_recv(false);
        post_send(false);

        std::size_t bytes;
        while ((bytes = m_recvbuf.gcount()) > 0)
        {
            on_recv(m_recvbuf.gptr(), bytes);
            m_recvbuf.gbump(bytes);
        }

        try_shutdown();

        if (m_both_closed.is_locked() && m_error)
        {
            on_disconnect(m_error);
            m_error.clear();
            m_valid = false;
        }
    }
Exemple #11
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;
    }
}
Exemple #12
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;
    }
}
Exemple #13
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;
    }

}
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;
    }
}
Exemple #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;
    }
}
Exemple #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);
}
Exemple #17
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);
    }
}
Exemple #18
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;
    }
}
int remote_thumbnail::disconnect()
{
	if (!m_connected)
		return error_not_connected;

	m_connected = false;

	DisconnectNamedPipe(m_pipe); 
	CloseHandle(m_pipe);

	on_disconnect();

	return 0;
}
void wifi_handle_event_cb(System_Event_t *evt) {
    printf("event %x\n", evt->event_id);
    switch (evt->event_id) {
        case EVENT_STAMODE_CONNECTED:
            printf("connect to ssid %s, channel %d\n",
                   evt->event_info.connected.ssid,
                   evt->event_info.connected.channel);
            break;
        case EVENT_STAMODE_DISCONNECTED:
            printf("disconnect from ssid %s, reason %d\n",
                   evt->event_info.disconnected.ssid,
                   evt->event_info.disconnected.reason);

            if (connected) {
                connected = false;
                on_disconnect();
            }

            break;
        case EVENT_STAMODE_AUTHMODE_CHANGE:
            printf("mode: %d -> %d\n",
                   evt->event_info.auth_change.old_mode,
                   evt->event_info.auth_change.new_mode);
            break;
        case EVENT_STAMODE_GOT_IP:
            printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
                   IP2STR(&evt->event_info.got_ip.ip),
                   IP2STR(&evt->event_info.got_ip.mask),
                   IP2STR(&evt->event_info.got_ip.gw));
            printf("\n");

            first_connect = false;
            connected = true;

            on_connect();

            break;
        case EVENT_SOFTAPMODE_STACONNECTED:
            printf("station: " MACSTR "join, AID = %d\n",
                   MAC2STR(evt->event_info.sta_connected.mac),
                   evt->event_info.sta_connected.aid);
            break;
        case EVENT_SOFTAPMODE_STADISCONNECTED:
            printf("station: " MACSTR "leave, AID = %d\n", MAC2STR(evt->event_info.sta_disconnected.mac),
                   evt->event_info.sta_disconnected.aid);
            break;
        default:
            break;
    }
}
Exemple #21
0
int on_event(struct rdma_cm_event *event)
{
	int r = 0;

	if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST)
		r = on_connect_request(event->id);
	else if (event->event == RDMA_CM_EVENT_ESTABLISHED)
		r = on_connection(event->id->context);
	else if (event->event == RDMA_CM_EVENT_DISCONNECTED)
		r = on_disconnect(event->id);
	else
		die("on_event: unknown event.");

	return r;
}
Exemple #22
0
void ble_vns_on_ble_evt(ble_vns_t * p_vns, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_vns, p_ble_evt);
            break;

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

        default:
            break;
    }
}
int on_event(struct rdma_cm_event *event)
{
  int r = 0;

  if (event->event == RDMA_CM_EVENT_ADDR_RESOLVED)
    r = on_addr_resolved(event->id);
  else if (event->event == RDMA_CM_EVENT_ROUTE_RESOLVED)
    r = on_route_resolved(event->id);
  else if (event->event == RDMA_CM_EVENT_ESTABLISHED)
    r = on_connection(event->id->context);
  else if (event->event == RDMA_CM_EVENT_DISCONNECTED)
    r = on_disconnect(event->id);
  else
    die("on_event: unknown event.");

  return r;
}
Exemple #24
0
void ble_lls_on_ble_evt(ble_lls_t * p_lls, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_lls);
            break;
        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_lls, p_ble_evt);
            break;
        case BLE_GAP_EVT_AUTH_STATUS:
            on_auth_status(p_lls, p_ble_evt);
            break;

        default:
            // No implementation needed.
            break;
    }
}
/**
 * @brief disconnect from UNIX socket
 */
void disconnect_unix(JNIEnv *env, jclass clazz _U_) {
  
  if(!connected)
    return;
  
  stop_notifier();
  
  pthread_mutex_lock(&write_lock);
  shutdown(sockfd, SHUT_RDWR);
  pthread_mutex_unlock(&write_lock);
  
  stop_reader();
  
  close(sockfd);
  
  connected = 0;
  
  on_disconnect(env);
}
Exemple #26
0
//event handler
int on_event(struct rdma_cm_id *id, struct rdma_cm_event *event)
{
  int r = 0;

  if (event->event == RDMA_CM_EVENT_ADDR_RESOLVED)
    r = on_addr_resolved(id);
  else if (event->event == RDMA_CM_EVENT_ROUTE_RESOLVED)
    r = on_route_resolved(id);
  else if (event->event == RDMA_CM_EVENT_ESTABLISHED)
    r = on_connection(id);
  else if (event->event == RDMA_CM_EVENT_DISCONNECTED)
    r = on_disconnect(id);
  else {
     pr_debug("on_event: %d\n", event->event);
   die("on_event: unknown event.");
  }

  return r;
}
void iss_on_ble_evt(iss_t * p_iss, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_iss, p_ble_evt);
            break;
            
        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_iss, p_ble_evt);
            break;
            
        case BLE_GATTS_EVT_WRITE:
            on_write(p_iss, p_ble_evt);
            break;
            
        default:
            break;
    }
}
Exemple #28
0
    device_status device::disconnect()
    {
        if (state() != device_state_value::not_ready)
            return device_status_value::not_ready;

        if (state() != device_state_value::faulted)
            return device_status_value::device_error;

        if (!is_connected())
            return device_status_value::ok;

        auto rc = on_disconnect();

        if (rc)
        {
            set_isConnected(false);
        }

        return rc;
    }
/**@brief Function for handling BLE events.
 *
 * @param[in]   p_dfu__nordic_       DFU (Nordic) Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
void ble_dfu__nordic__on_ble_evt(ble_dfu__nordic__t * p_dfu__nordic_, ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_dfu__nordic_, p_ble_evt);
            break;
        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_dfu__nordic_, p_ble_evt);
            break;
        case BLE_GATTS_EVT_WRITE:
            on_write(p_dfu__nordic_, &p_ble_evt->evt.gatts_evt.params.write);
            break;
         case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
            on_rw_authorize_request(p_dfu__nordic_, &p_ble_evt->evt.gatts_evt);
            break;
        default:
            //No implementation needed.
            break;
    }
}
Exemple #30
0
int on_event(struct rdma_cm_event *event)
{
  int r = 0;

  printf("event id: %d\n", event->event);
  if (event->event == RDMA_CM_EVENT_ADDR_RESOLVED)
    r = on_addr_resolved(event->id);
  else if (event->event == RDMA_CM_EVENT_ROUTE_RESOLVED)
    r = on_route_resolved(event->id);
  else if (event->event == RDMA_CM_EVENT_ESTABLISHED)
    r = on_connection(event->id);
  else if (event->event == RDMA_CM_EVENT_DISCONNECTED)
    r = on_disconnect(event->id);
  else
    fprintf(stderr, "unknow event id: %d\n", event->event);
    fprintf(stderr, "exit");
    exit(1);
  //    die("on_event: unknown event a");

  return r;
}