if (clifd < 0)
return true;
- ret = aul_worker_add_io_job(worker, "client", clifd, cond,
- __received_event_cb, worker);
+ ret = aul_worker_add_io_job(worker, "client", clifd, cond, true,
+ __received_event_cb, worker);
if (ret < 0) {
_E("Failed to add io job. error(%d)", ret);
__remove_client_channel(channel);
__destroy_client_channel(channel);
- close(clifd);
return true;
}
}
ret = aul_worker_add_io_job(__context.worker, "server", fd, AUL_IO_IN,
- __connected_event_cb, __context.worker);
+ false, __connected_event_cb, __context.worker);
if (ret < 0) {
__finalize_context();
return ret;
struct job_s *job = (struct job_s *)data;
GSource *source;
GMainContext *context;
- GError *error = NULL;
-
- if (job->channel) {
- g_io_channel_shutdown(job->channel, TRUE, &error);
- if (error) {
- _E("g_io_channel_shutdown() is failed. error(%s)",
- error->message);
- g_error_free(error);
- }
+
+ if (job->channel)
g_io_channel_unref(job->channel);
- }
if (job->tag) {
context = g_main_context_get_thread_default();
}
int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
- int fd, int condition, aul_worker_io_job_cb callback,
+ int fd, int condition, bool do_close,
+ aul_worker_io_job_cb callback,
void *user_data)
{
GIOCondition cond = __convert_aul_io_condition(condition);
channel = g_io_channel_unix_new(fd);
if (!channel) {
_E("Failed to create GIOChannel");
+ if (do_close)
+ close(fd);
+
return AUL_R_ENOMEM;
}
+ g_io_channel_set_close_on_unref(channel, do_close);
source = g_io_create_watch(channel, cond);
if (!source) {
_E("Failed to create GSource");
void aul_worker_destroy(aul_worker_h handle);
int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
- int fd, int condition, aul_worker_io_job_cb callback,
- void *user_data);
+ int fd, int condition, bool do_close,
+ aul_worker_io_job_cb callback, void *user_data);
void aul_worker_remove_io_job(aul_worker_h handle, int fd);