BT_DBG("-");
}
-static void __connected_cb(l2cap_le_remote_client_info_t *client_info,
+static void __connected_cb(int result, l2cap_le_remote_client_info_t *client_info,
bt_event_info_t *event_info)
{
bluetooth_l2cap_le_connection_t conn_info;
BT_INFO_C("Connected [L2CAP_LE Server] psm %d", server_info->psm);
_bt_common_event_cb(BLUETOOTH_EVENT_L2CAP_LE_CONNECTED,
- BLUETOOTH_ERROR_NONE, &conn_info,
+ result, &conn_info,
event_info->cb, event_info->user_data);
}
int client_fd;
char buf[BLUETOOTH_SOCK_CONNECT_INFO_LEN];
unsigned char addr[BT_ADDRESS_LENGTH_MAX];
+ int result = BLUETOOTH_ERROR_NONE;
bt_event_info_t *event_info;
GIOChannel *io;
BT_INFO("New client [%s] connection with socket_fd: %d, server_id: %d",
rem_client->addr, rem_client->sock_fd, rem_client->server_id);
- io = g_io_channel_unix_new(rem_client->sock_fd);
- g_io_channel_set_encoding(io, NULL, NULL);
- g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
- rem_client->watch_id = g_io_add_watch(io,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- __data_received_cb, rem_client);
- g_io_channel_unref(io);
+ if (client_fd >= 0) {
+ io = g_io_channel_unix_new(rem_client->sock_fd);
+ g_io_channel_set_encoding(io, NULL, NULL);
+ g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
+ rem_client->watch_id = g_io_add_watch(io,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ __data_received_cb, rem_client);
+ g_io_channel_unref(io);
+
+ server_info->conn_list = g_slist_append(server_info->conn_list, rem_client);
+ } else {
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
- server_info->conn_list = g_slist_append(server_info->conn_list, rem_client);
event_info = _bt_event_get_cb_data(BT_L2CAP_LE_SERVER_EVENT);
if (event_info)
- __connected_cb(rem_client, event_info);
+ __connected_cb(result, rem_client, event_info);
+
+ if (result != BLUETOOTH_ERROR_NONE)
+ g_free(rem_client);
return TRUE;
return FALSE;
}
-static void __connected_cb(rfcomm_info_t *info, rfcomm_conn_t *conn,
+static void __connected_cb(int result, rfcomm_info_t *info, rfcomm_conn_t *conn,
bt_event_info_t *event_info)
{
bluetooth_rfcomm_connection_t conn_info;
BT_ERR("Fail to send the connection info");
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
- BLUETOOTH_ERROR_NONE, &conn_info,
+ result, &conn_info,
event_info->cb, event_info->user_data);
}
rfcomm_conn_t *conn;
GIOChannel *data_io;
bt_event_info_t *event_info;
+ int result = BLUETOOTH_ERROR_NONE;
BT_INFO("%s %d", path, fd);
conn = g_new0(rfcomm_conn_t, 1);
conn->fd = fd;
memcpy(&conn->addr, addr, sizeof(bluetooth_device_address_t));
- info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
-
- data_io = g_io_channel_unix_new(conn->fd);
- g_io_channel_set_encoding(data_io, NULL, NULL);
- g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
+ if (fd >= 0) {
+ data_io = g_io_channel_unix_new(conn->fd);
+ g_io_channel_set_encoding(data_io, NULL, NULL);
+ g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
+ conn->watch_id = g_io_add_watch(data_io,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ __data_received_cb, info);
+ g_io_channel_unref(data_io);
- conn->watch_id = g_io_add_watch(data_io,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- __data_received_cb, info);
-
- g_io_channel_unref(data_io);
+ info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
+ } else {
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
if (event_info)
- __connected_cb(info, conn, event_info);
+ __connected_cb(result, info, conn, event_info);
+
+ if (result != BLUETOOTH_ERROR_NONE)
+ g_free(conn);
return 0;
}
BT_DBG("-");
}
-static void __connected_cb(rfcomm_remote_client_info_t *client_info, bt_event_info_t *event_info)
+static void __connected_cb(int result, rfcomm_remote_client_info_t *client_info, bt_event_info_t *event_info)
{
bluetooth_rfcomm_connection_t conn_info;
rfcomm_server_info_t *server_info;
BT_INFO_C("Connected [RFCOMM Server]");
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
- BLUETOOTH_ERROR_NONE, &conn_info,
+ result, &conn_info,
event_info->cb, event_info->user_data);
}
int client_fd;
char buf[BLUETOOTH_SOCK_CONNECT_INFO_LEN];
unsigned char addr[BT_ADDRESS_LENGTH_MAX];
+ int result = BLUETOOTH_ERROR_NONE;
bt_event_info_t *event_info;
GIOChannel *io;
BT_INFO("New client [%s] connection with socket_fd: %d, server_id: %d",
rem_client->addr, rem_client->sock_fd, rem_client->server_id);
- io = g_io_channel_unix_new(rem_client->sock_fd);
- g_io_channel_set_encoding(io, NULL, NULL);
- g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
- rem_client->watch_id = g_io_add_watch(io,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- __data_received_cb, rem_client);
- g_io_channel_unref(io);
+ if (client_fd >= 0) {
+ io = g_io_channel_unix_new(rem_client->sock_fd);
+ g_io_channel_set_encoding(io, NULL, NULL);
+ g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
+ rem_client->watch_id = g_io_add_watch(io,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ __data_received_cb, rem_client);
+ g_io_channel_unref(io);
+
+ server_info->conn_list = g_slist_append(server_info->conn_list, rem_client);
+ } else {
+ result = BLUETOOTH_ERROR_INTERNAL;
+ }
- server_info->conn_list = g_slist_append(server_info->conn_list, rem_client);
event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
if (event_info)
- __connected_cb(rem_client, event_info);
+ __connected_cb(result, rem_client, event_info);
+
+ if (result != BLUETOOTH_ERROR_NONE)
+ g_free(rem_client);
return TRUE;