Skip to content

Instantly share code, notes, and snippets.

@slingamn
Last active August 31, 2017 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slingamn/8b852215272a902618fecead52396be4 to your computer and use it in GitHub Desktop.
Save slingamn/8b852215272a902618fecead52396be4 to your computer and use it in GitHub Desktop.
commit 4a6a8bf7e6a58bd9a1d372065cfe6ff74b1e0e19
Author: Shivaram Lingamneni <slingamn@cs.stanford.edu>
Date: Thu Aug 31 00:37:07 2017 -0400
patch to read ssl in a loop
diff --git a/libpurple/protocols/irc/irc.c b/libpurple/protocols/irc/irc.c
index f101cbe..9a782c2 100644
--- a/libpurple/protocols/irc/irc.c
+++ b/libpurple/protocols/irc/irc.c
@@ -674,45 +674,47 @@ static void irc_input_cb_ssl(gpointer data, PurpleSslConnection *gsc,
PurpleConnection *gc = data;
struct irc_conn *irc = gc->proto_data;
int len;
if(!g_list_find(purple_connections_get_all(), gc)) {
purple_ssl_close(gsc);
return;
}
+ while (1) {
+ /* resize to allow a read of at least IRC_INITIAL_BUFSIZE - 1 bytes */
if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) {
irc->inbuflen += IRC_INITIAL_BUFSIZE;
irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen);
}
-
len = purple_ssl_read(gsc, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1);
if (len < 0 && errno == EAGAIN) {
/* Try again later */
return;
} else if (len < 0) {
gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"),
g_strerror(errno));
purple_connection_error_reason (gc,
PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
g_free(tmp);
return;
} else if (len == 0) {
purple_connection_error_reason (gc,
PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
_("Server closed the connection"));
return;
}
read_input(irc, len);
+ }
}
static void irc_input_cb(gpointer data, gint source, PurpleInputCondition cond)
{
PurpleConnection *gc = data;
struct irc_conn *irc = gc->proto_data;
int len;
if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) {
irc->inbuflen += IRC_INITIAL_BUFSIZE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment