static void connect_cb(GObject *source, GAsyncResult *res, gpointer user_data) { GSocketConnection *socket_conn; PnNode *conn; GError *error = NULL; conn = PN_NODE(user_data); socket_conn = g_socket_client_connect_to_host_finish(G_SOCKET_CLIENT(source), res, &error); g_object_unref(source); if (error) { g_error_free(error); return; } g_object_ref(conn); if (socket_conn) { GSocket *socket; GInputStream *input; conn->socket_conn = socket_conn; socket = g_socket_connection_get_socket(socket_conn); conn->status = PN_NODE_STATUS_OPEN; input = g_io_stream_get_input_stream (G_IO_STREAM (conn->socket_conn)); g_object_ref (conn); g_input_stream_read_async (input, conn->input_buffer, PN_BUF_LEN, G_PRIORITY_DEFAULT, NULL, read_cb, conn); } else { conn->error = g_error_new_literal(PN_NODE_ERROR, PN_NODE_ERROR_OPEN, "Unable to connect"); pn_node_error(conn); } { PnNodeClass *class; class = g_type_class_peek(PN_NODE_TYPE); g_signal_emit(G_OBJECT(conn), class->open_sig, 0, conn); } g_object_unref(conn); }
gboolean xr_client_open(xr_client_conn* conn, const char* uri, GError** err) { GError* local_err = NULL; g_return_val_if_fail(conn != NULL, FALSE); g_return_val_if_fail(uri != NULL, FALSE); g_return_val_if_fail(!conn->is_open, FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); xr_trace(XR_DEBUG_CLIENT_TRACE, "(conn=%p, uri=%s)", conn, uri); // parse URI format: http://host:8080/RES g_free(conn->host); g_free(conn->resource); conn->host = NULL; conn->resource = NULL; if (!_parse_uri(uri, &conn->secure, &conn->host, &conn->resource)) { g_set_error(err, XR_CLIENT_ERROR, XR_CLIENT_ERROR_FAILED, "invalid URI format: %s", uri); return FALSE; } // enable/disable TLS if (conn->secure) { g_socket_client_set_tls(conn->client, TRUE); g_socket_client_set_tls_validation_flags(conn->client, G_TLS_CERTIFICATE_VALIDATE_ALL & ~G_TLS_CERTIFICATE_UNKNOWN_CA & ~G_TLS_CERTIFICATE_BAD_IDENTITY); } else { g_socket_client_set_tls(conn->client, FALSE); } conn->conn = g_socket_client_connect_to_host(conn->client, conn->host, 80, NULL, &local_err); if (local_err) { g_propagate_prefixed_error(err, local_err, "Connection failed: "); return FALSE; } xr_set_nodelay(g_socket_connection_get_socket(conn->conn)); conn->http = xr_http_new(G_IO_STREAM(conn->conn)); g_free(conn->session_id); conn->session_id = g_strdup_printf("%08x%08x%08x%08x", g_random_int(), g_random_int(), g_random_int(), g_random_int()); conn->is_open = 1; xr_client_set_http_header(conn, "X-SESSION-ID", conn->session_id); return TRUE; }
static void ekg_gnutls_new_session( GSocketClient *sockclient, GSocketConnection *sock, struct ekg_connection_starter *cs) { gnutls_session_t s; gnutls_certificate_credentials_t cred; struct ekg_gnutls_connection *conn = g_slice_new(struct ekg_gnutls_connection); struct ekg_gnutls_connection_starter *gcs = g_slice_new(struct ekg_gnutls_connection_starter); g_assert(!gnutls_certificate_allocate_credentials(&cred)); g_assert(!gnutls_init(&s, GNUTLS_CLIENT)); g_assert(!gnutls_priority_set_direct(s, "PERFORMANCE", NULL)); /* XXX */ g_assert(!gnutls_credentials_set(s, GNUTLS_CRD_CERTIFICATE, cred)); gnutls_transport_set_pull_function(s, ekg_gnutls_pull); gnutls_transport_set_push_function(s, ekg_gnutls_push); gnutls_transport_set_ptr(s, conn); gcs->parent = cs; gcs->conn = conn; gcs->sockclient = sockclient; conn->session = s; conn->cred = cred; conn->connection_error = NULL; conn->connection = get_connection_by_outstream( ekg_connection_add( sock, g_io_stream_get_input_stream(G_IO_STREAM(sock)), g_io_stream_get_output_stream(G_IO_STREAM(sock)), ekg_gnutls_handle_handshake_input, ekg_gnutls_handle_handshake_failure, gcs) ); g_assert(conn->connection); ekg_gnutls_async_handshake(gcs); }
static gboolean handler (GThreadedSocketService *service, GSocketConnection *connection, GSocketListener *listener, gpointer user_data) { GOutputStream *out; GInputStream *in; char buffer[1024]; gssize size; out = g_io_stream_get_output_stream (G_IO_STREAM (connection)); in = g_io_stream_get_input_stream (G_IO_STREAM (connection)); g_output_stream_write_all (out, MESSAGE, strlen (MESSAGE), NULL, NULL, NULL); while (0 < (size = g_input_stream_read (in, buffer, sizeof buffer, NULL, NULL))) g_output_stream_write (out, buffer, size, NULL, NULL); return TRUE; }
static void on_io_closed (GObject *stream, GAsyncResult *result, gpointer user_data) { GError *error = NULL; if (!g_io_stream_close_finish (G_IO_STREAM (stream), result, &error)) { if (!should_suppress_output_error (error)) g_message ("http close error: %s", error->message); g_error_free (error); } }
//------------------------------------------------------------------------------ gboolean onConnection(GSocketService *server, GSocketConnection *connection, GObject *sourceObject, gpointer userData) { g_print("connection\n"); GInputStream *istream = g_io_stream_get_input_stream(G_IO_STREAM(connection)); ConnData *data = new ConnData; ostream = g_io_stream_get_output_stream(G_IO_STREAM(connection)); data->connection = (GSocketConnection*)g_object_ref(connection); g_input_stream_read_async(istream, data->message, sizeof (data->message), G_PRIORITY_DEFAULT, NULL, onMessage, data); return FALSE; }
/* command socket callback */ gboolean socket_callback(GSocketService * service, GSocketConnection * conn, GObject * source_object, gpointer user_data) { video_server_t * server = (video_server_t *)user_data; gchar message[128]; guint64 value; GInputStream * istream = g_io_stream_get_input_stream(G_IO_STREAM(conn)); g_input_stream_read(istream, message, 128, NULL, NULL); /* Supported commands: * * "b 5000" set bitrate to 5 Mbps * "i 3000" set I-frame interval in msec * "f 30" set framerate in frames/sec * "s 640x360" set frame size */ gchar **cmd_str = g_strsplit(message, " ", 0); if (g_strv_length(cmd_str) != 2) { fprintf(stderr, "Incorrect command syntax: %s", message); return FALSE; } switch (cmd_str[0][0]) { case 'b': value = g_ascii_strtoull(cmd_str[1], NULL, 0); video_server_set_bitrate(server, (unsigned int) value); break; case 'i': value = g_ascii_strtoull(cmd_str[1], NULL, 0); video_server_set_iframe_period(server, (unsigned int) value); break; case 'f': value = g_ascii_strtoull(cmd_str[1], NULL, 0); video_server_set_framerate(server, (unsigned int) value); break; case 's': get_frame_size(cmd_str[1], server->conf); video_server_reset_frame_size(server); break; } g_strfreev(cmd_str); return FALSE; }
static void stream_tube_connection_closed_cb (GObject *source, GAsyncResult *result, gpointer user_data) { GError *error = NULL; if (!g_io_stream_close_finish (G_IO_STREAM (source), result, &error)) { DEBUG ("Failed to close connection: %s", error->message); g_error_free (error); return; } }
static void connectedCallback(GSocketClient* client, GAsyncResult* result, void* id) { // Always finish the connection, even if this SocketStreamHandle was deactivated earlier. GOwnPtr<GError> error; GSocketConnection* socketConnection = g_socket_client_connect_to_host_finish(client, result, &error.outPtr()); // The SocketStreamHandle has been deactivated, so just close the connection, ignoring errors. SocketStreamHandle* handle = getHandleFromId(id); if (!handle) { g_io_stream_close(G_IO_STREAM(socketConnection), 0, &error.outPtr()); return; } handle->connected(socketConnection, error.get()); }
long long seekFile(PlatformFileHandle handle, long long offset, FileSeekOrigin origin) { GSeekType seekType = G_SEEK_SET; switch (origin) { case SeekFromBeginning: seekType = G_SEEK_SET; break; case SeekFromCurrent: seekType = G_SEEK_CUR; break; case SeekFromEnd: seekType = G_SEEK_END; break; default: ASSERT_NOT_REACHED(); } if (!g_seekable_seek(G_SEEKABLE(g_io_stream_get_input_stream(G_IO_STREAM(handle))), offset, seekType, 0, 0)) { return -1; } return g_seekable_tell(G_SEEKABLE(g_io_stream_get_input_stream(G_IO_STREAM(handle)))); }
static void on_io_closed (GObject *stream, GAsyncResult *result, gpointer user_data) { GError *error = NULL; if (!g_io_stream_close_finish (G_IO_STREAM (stream), result, &error)) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE)) g_debug ("http close error: %s", error->message); else g_message ("http close error: %s", error->message); g_error_free (error); } }
/** * g_tls_client_connection_new: * @base_io_stream: the #GIOStream to wrap * @server_identity: (allow-none): the expected identity of the server * @error: #GError for error reporting, or %NULL to ignore. * * Creates a new #GTlsClientConnection wrapping @base_io_stream (which * must have pollable input and output streams) which is assumed to * communicate with the server identified by @server_identity. * * Returns: (transfer full) (type GTlsClientConnection): the new * #GTlsClientConnection, or %NULL on error * * Since: 2.28 */ GIOStream * g_tls_client_connection_new (GIOStream *base_io_stream, GSocketConnectable *server_identity, GError **error) { GObject *conn; GTlsBackend *backend; backend = g_tls_backend_get_default (); conn = g_initable_new (g_tls_backend_get_client_connection_type (backend), NULL, error, "base-io-stream", base_io_stream, "server-identity", server_identity, NULL); return G_IO_STREAM (conn); }
static gboolean on_incoming_connection (GSocketService * service, GSocketConnection * connection, GObject * source_object, gpointer user_data) { GInputStream * input; void * buf; input = g_io_stream_get_input_stream (G_IO_STREAM (connection)); buf = g_malloc (1); g_input_stream_read_async (input, buf, 1, G_PRIORITY_DEFAULT, NULL, on_read_ready, NULL); return TRUE; }
/** * g_tls_server_connection_new: * @base_io_stream: the #GIOStream to wrap * @certificate: (allow-none): the default server certificate, or %NULL * @error: #GError for error reporting, or %NULL to ignore. * * Creates a new #GTlsServerConnection wrapping @base_io_stream (which * must have pollable input and output streams). * * Return value: (transfer full): the new #GTlsServerConnection, or %NULL on error * * Since: 2.28 */ GIOStream * g_tls_server_connection_new (GIOStream *base_io_stream, GTlsCertificate *certificate, GError **error) { GObject *conn; GTlsBackend *backend; backend = g_tls_backend_get_default (); conn = g_initable_new (g_tls_backend_get_server_connection_type (backend), NULL, error, "base-io-stream", base_io_stream, "certificate", certificate, NULL); return G_IO_STREAM (conn); }
static void gum_duk_debug_channel_add_session (GumDukDebugChannel * self, GSocketConnection * connection) { gboolean is_first_session; GumDukDebugSession * session; is_first_session = self->sessions == NULL; session = gum_duk_debug_session_new (self, G_IO_STREAM (connection)); self->sessions = g_slist_prepend (self->sessions, session); gum_duk_debug_session_open (session); if (is_first_session) gum_duk_debug_channel_attach (self); }
static void jetdirect_connection_test_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GSocketConnection *connection; PpHostPrivate *priv; PpPrintDevice *device; JetDirectData *data; gpointer result; GError *error = NULL; GTask *task = G_TASK (user_data); data = g_task_get_task_data (task); connection = g_socket_client_connect_to_host_finish (G_SOCKET_CLIENT (source_object), res, &error); if (connection != NULL) { g_io_stream_close (G_IO_STREAM (connection), NULL, NULL); g_object_unref (connection); priv = data->host->priv; device = g_new0 (PpPrintDevice, 1); device->device_class = g_strdup ("network"); device->device_uri = g_strdup_printf ("socket://%s:%d", priv->hostname, data->port); /* Translators: The found device is a JetDirect printer */ device->device_name = g_strdup (_("JetDirect Printer")); device->host_name = g_strdup (priv->hostname); device->host_port = data->port; device->acquisition_method = ACQUISITION_METHOD_JETDIRECT; data->devices->devices = g_list_append (data->devices->devices, device); } result = data->devices; data->devices = NULL; g_task_return_pointer (task, result, (GDestroyNotify) pp_devices_list_free); g_object_unref (task); }
static gboolean identd_incoming_cb (GSocketService *service, GSocketConnection *conn, GObject *source, gpointer userdata) { GInputStream *stream; ident_info *info; info = g_new0 (ident_info, 1); info->conn = conn; g_object_ref (conn); stream = g_io_stream_get_input_stream (G_IO_STREAM (conn)); g_input_stream_read_async (stream, info->read_buf, sizeof (info->read_buf), G_PRIORITY_DEFAULT, NULL, (GAsyncReadyCallback)identd_read_ready, info); return TRUE; }
gboolean g_vfs_ftp_connection_open_data_connection (GVfsFtpConnection *conn, GSocketAddress * addr, GCancellable * cancellable, GError ** error) { g_return_val_if_fail (conn != NULL, FALSE); g_return_val_if_fail (conn->data == NULL, FALSE); g_vfs_ftp_connection_stop_listening (conn); conn->data = G_IO_STREAM (g_socket_client_connect (conn->client, G_SOCKET_CONNECTABLE (addr), cancellable, error)); return conn->data != NULL; }
int main (int argc, char *argv[]) { /* initialize glib */ //g_type_init (); GError * error = NULL; /* create a new connection */ GSocketConnection * connection = NULL; GSocketClient * client = g_socket_client_new(); /* connect to the host */ connection = g_socket_client_connect_to_host (client, (gchar*)"localhost", 2345, /* your port goes here */ NULL, &error); /* don't forget to check for errors */ if (error != NULL) { g_error (error->message); } else { g_print ("Connection successful!\n"); } /* use the connection */ //GInputStream * istream = g_io_stream_get_input_stream (G_IO_STREAM (connection)); GOutputStream * ostream = g_io_stream_get_output_stream (G_IO_STREAM (connection)); g_output_stream_write (ostream, "Hello server!", /* your message goes here */ 13, /* length of your message */ NULL, &error); /* don't forget to check for errors */ if (error != NULL) { g_error (error->message); } return 0; }
static void zpj_download_stream_ready (GObject *source, GAsyncResult *res, gpointer user_data) { GError *error = NULL; PdfLoadJob *job = (PdfLoadJob *) user_data; const gchar *name; const gchar *extension; job->stream = zpj_skydrive_download_file_to_stream_finish (ZPJ_SKYDRIVE (source), res, &error); if (error != NULL) { pdf_load_job_complete_error (job, error); return; } name = zpj_skydrive_entry_get_name (job->zpj_entry); extension = gd_filename_get_extension_offset (name); /* If it is not a PDF, we need to convert it afterwards. * http://msdn.microsoft.com/en-us/library/live/hh826545#fileformats */ if (g_strcmp0 (extension, ".pdf") != 0) { GFileIOStream *iostream; job->download_file = g_file_new_tmp (NULL, &iostream, &error); if (error != NULL) { pdf_load_job_complete_error (job, error); return; } /* We don't need the iostream. */ g_io_stream_close (G_IO_STREAM (iostream), NULL, NULL); } else job->download_file = g_file_new_for_path (job->pdf_path); g_file_replace_async (job->download_file, NULL, FALSE, G_FILE_CREATE_PRIVATE, G_PRIORITY_DEFAULT, job->cancellable, file_replace_ready_cb, job); }
/** * Stream write buffer to a temporary file (in one go) * * @param buffer The buffer to write * @param count Size of the buffer to write * * @return the filename of the buffer that was written */ gchar* util_write_tmp_file_from_bytes ( const void *buffer, gsize count ) { GFileIOStream *gios; GError *error = NULL; gchar *tmpname = NULL; #if GLIB_CHECK_VERSION(2,32,0) GFile *gf = g_file_new_tmp ( "vik-tmp.XXXXXX", &gios, &error ); tmpname = g_file_get_path (gf); #else gint fd = g_file_open_tmp ( "vik-tmp.XXXXXX", &tmpname, &error ); if ( error ) { g_warning ( "%s", error->message ); g_error_free ( error ); return NULL; } gios = g_file_open_readwrite ( g_file_new_for_path (tmpname), NULL, &error ); if ( error ) { g_warning ( "%s", error->message ); g_error_free ( error ); return NULL; } #endif gios = g_file_open_readwrite ( g_file_new_for_path (tmpname), NULL, &error ); if ( error ) { g_warning ( "%s", error->message ); g_error_free ( error ); return NULL; } GOutputStream *gos = g_io_stream_get_output_stream ( G_IO_STREAM(gios) ); if ( g_output_stream_write ( gos, buffer, count, NULL, &error ) < 0 ) { g_critical ( "Couldn't write tmp %s file due to %s", tmpname, error->message ); g_free (tmpname); tmpname = NULL; } g_output_stream_close ( gos, NULL, &error ); g_object_unref ( gios ); return tmpname; }
static void _close_ready(GObject *source_object, GAsyncResult *res, gpointer user_data) { GIOStream *io_stream = G_IO_STREAM(source_object); GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT(user_data); IdleServerConnection *conn = IDLE_SERVER_CONNECTION(g_async_result_get_source_object(G_ASYNC_RESULT(result))); IdleServerConnectionPrivate *priv = IDLE_SERVER_CONNECTION_GET_PRIVATE(conn); GError *error = NULL; change_state(conn, SERVER_CONNECTION_STATE_NOT_CONNECTED, priv->reason); g_object_unref(conn); if (!g_io_stream_close_finish(io_stream, res, &error)) { IDLE_DEBUG("g_io_stream_close failed: %s", error->message); g_simple_async_result_set_error(result, TP_ERROR, TP_ERROR_NETWORK_ERROR, "%s", error->message); g_error_free(error); } g_simple_async_result_complete(result); g_object_unref(result); }
static gboolean do_connect(MegaHttpClient* http_client, GCancellable* cancellable, GError** err) { GError* local_err = NULL; g_return_val_if_fail(MEGA_IS_HTTP_CLIENT(http_client), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); MegaHttpClientPrivate* priv = http_client->priv; do_disconnect(http_client); // enable/disable TLS if (priv->https) { if (!g_tls_backend_supports_tls(g_tls_backend_get_default())) { g_set_error(err, MEGA_HTTP_CLIENT_ERROR, MEGA_HTTP_CLIENT_ERROR_OTHER, "TLS backend not found, please install glib-networking."); return FALSE; } g_socket_client_set_tls(priv->client, TRUE); } else { g_socket_client_set_tls(priv->client, FALSE); } priv->conn = g_socket_client_connect_to_host(priv->client, priv->host, priv->port, cancellable, &local_err); if (!priv->conn) { g_propagate_prefixed_error(err, local_err, "Connection failed: "); return FALSE; } GDataInputStream* data_stream = g_data_input_stream_new(g_io_stream_get_input_stream(G_IO_STREAM(http_client->priv->conn))); g_data_input_stream_set_newline_type(data_stream, G_DATA_STREAM_NEWLINE_TYPE_ANY); priv->istream = G_INPUT_STREAM(data_stream); priv->ostream = g_object_ref(g_io_stream_get_output_stream(G_IO_STREAM(http_client->priv->conn))); return TRUE; }
void SocketStreamHandle::platformClose() { // We remove this handle from the active handles list first, to disable all callbacks. deactivateHandle(this); stopWaitingForSocketWritability(); if (m_socketConnection) { GOwnPtr<GError> error; g_io_stream_close(G_IO_STREAM(m_socketConnection.get()), 0, &error.outPtr()); if (error) m_client->didFail(this, SocketStreamError(error->code)); // FIXME: Provide a sensible error. m_socketConnection = 0; } m_outputStream = 0; m_inputStream = 0; delete m_readBuffer; m_client->didClose(this); }
static void send_reply (BroadwayClient *client, BroadwayRequest *request, BroadwayReply *reply, gsize size, guint32 type) { GOutputStream *output; reply->base.size = size; reply->base.in_reply_to = request ? request->base.serial : 0; reply->base.type = type; output = g_io_stream_get_output_stream (G_IO_STREAM (client->connection)); if (!g_output_stream_write_all (output, reply, size, NULL, NULL, NULL)) { g_printerr ("can't write to client"); client_disconnect_in_idle (client); } }
void SocketStreamHandle::connectedCallback(GSocketClient* client, GAsyncResult* result, SocketStreamHandle* handle) { RefPtr<SocketStreamHandle> protectedThis = adoptRef(handle); // Always finish the connection, even if this SocketStreamHandle was cancelled earlier. GUniqueOutPtr<GError> error; GRefPtr<GSocketConnection> socketConnection = adoptGRef(g_socket_client_connect_to_host_finish(client, result, &error.outPtr())); // The SocketStreamHandle has been cancelled, so just close the connection, ignoring errors. if (g_cancellable_is_cancelled(handle->m_cancellable.get())) { if (socketConnection) g_io_stream_close(G_IO_STREAM(socketConnection.get()), nullptr, nullptr); return; } if (error) handle->didFail(SocketStreamError(error->code, error->message)); else handle->connected(WTFMove(socketConnection)); }
GVfsAfpReply * g_vfs_afp_connection_get_server_info (GVfsAfpConnection *afp_connection, GCancellable *cancellable, GError **error) { GVfsAfpConnectionPrivate *priv = afp_connection->priv; GSocketClient *client; GIOStream *conn; gboolean res; DSIHeader dsi_header; char *data; client = g_socket_client_new (); conn = G_IO_STREAM (g_socket_client_connect (client, priv->addr, cancellable, error)); g_object_unref (client); if (!conn) return NULL; res = send_request_sync (g_io_stream_get_output_stream (conn), DSI_GET_STATUS, 0, 0, 0, NULL, cancellable, error); if (!res) { g_object_unref (conn); return NULL; } res = read_reply_sync (g_io_stream_get_input_stream (conn), &dsi_header, &data, cancellable, error); if (!res) { g_object_unref (conn); return NULL; } g_object_unref (conn); return g_vfs_afp_reply_new (dsi_header.errorCode, data, dsi_header.totalDataLength, TRUE); }
int main(int argc, char *argv[]) { LibWCRelay *relay = libwc_relay_new(); GSocketClient *socket_client = g_socket_client_new(); GSocketConnection *socket_connection; gboolean result; gchar *ping_result; GError *error = NULL; if (argc < 2) { fprintf(stderr, "Usage: test-client <host[:port]>\n"); exit(1); } socket_connection = g_socket_client_connect_to_host(socket_client, argv[1], 49153, NULL, &error); END_IF_FAIL(socket_connection != NULL); libwc_relay_password_set(relay, "test"); libwc_relay_connection_set(relay, G_IO_STREAM(socket_connection), g_socket_connection_get_socket(socket_connection)); result = libwc_relay_connection_init(relay, NULL, &error); if (result) printf("Connection successful!\n"); else { fprintf(stderr, "Connection unsuccessful: %s\n", error->message); exit(1); } ping_result = libwc_relay_ping(relay, NULL, &error, TEST_PING_MESSAGE); if (ping_result && strcmp(ping_result, TEST_PING_MESSAGE) == 0) printf("Ping successful!\n"); else { fprintf(stderr, "Ping unsuccessful: %s\n", error->message); exit(1); } }
gchar* codeslayer_utils_get_file_path (const gchar *folder_path, const gchar *file_name) { gchar *file_path; GFile *file; file_path = g_build_filename (folder_path, file_name, NULL); file = g_file_new_for_path (file_path); if (!g_file_query_exists (file, NULL)) { GFileIOStream *stream; stream = g_file_create_readwrite (file, G_FILE_CREATE_NONE, NULL, NULL); g_io_stream_close (G_IO_STREAM (stream), NULL, NULL); g_object_unref (stream); } g_object_unref (file); return file_path; }
void SocketStreamHandle::platformClose() { LOG(Network, "SocketStreamHandle %p platformClose", this); // We remove this handle from the active handles list first, to disable all callbacks. deactivateHandle(this); stopWaitingForSocketWritability(); if (m_socketConnection) { GUniqueOutPtr<GError> error; g_io_stream_close(G_IO_STREAM(m_socketConnection.get()), 0, &error.outPtr()); if (error) m_client->didFailSocketStream(this, SocketStreamError(error->code, error->message)); m_socketConnection = 0; } m_outputStream = 0; m_inputStream = 0; m_readBuffer = nullptr; m_client->didCloseSocketStream(this); }