Trying to make connections more robust.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4020 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
29
src/ssb.js.c
29
src/ssb.js.c
@ -262,6 +262,19 @@ static JSValue _tf_ssb_getConnection(JSContext* context, JSValueConst this_val,
|
||||
return JS_DupValue(context, tf_ssb_connection_get_object(connection));
|
||||
}
|
||||
|
||||
static JSValue _tf_ssb_closeConnection(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
|
||||
const char* id = JS_ToCString(context, argv[0]);
|
||||
tf_ssb_connection_t* connection = tf_ssb_connection_get(ssb, id);
|
||||
if (connection)
|
||||
{
|
||||
tf_ssb_connection_close(connection);
|
||||
}
|
||||
JS_FreeCString(context, id);
|
||||
return connection ? JS_TRUE : JS_FALSE;
|
||||
}
|
||||
|
||||
typedef struct _sqlStream_callback_t
|
||||
{
|
||||
JSContext* context;
|
||||
@ -388,10 +401,17 @@ static JSValue _tf_ssb_connect(JSContext* context, JSValueConst this_val, int ar
|
||||
int32_t port_int = 0;
|
||||
JS_ToInt32(context, &port_int, port);
|
||||
const char* pubkey_str = JS_ToCString(context, pubkey);
|
||||
uint8_t pubkey_bin[k_id_bin_len];
|
||||
printf("Connecting to %s:%d\n", address_str, port_int);
|
||||
tf_ssb_id_str_to_bin(pubkey_bin, pubkey_str);
|
||||
tf_ssb_connect(ssb, address_str, port_int, pubkey_bin);
|
||||
if (pubkey_str)
|
||||
{
|
||||
printf("Connecting to %s:%d\n", address_str, port_int);
|
||||
uint8_t pubkey_bin[k_id_bin_len];
|
||||
tf_ssb_id_str_to_bin(pubkey_bin, pubkey_str);
|
||||
tf_ssb_connect(ssb, address_str, port_int, pubkey_bin);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Not connecting to null.\n");
|
||||
}
|
||||
JS_FreeCString(context, pubkey_str);
|
||||
JS_FreeCString(context, address_str);
|
||||
JS_FreeValue(context, address);
|
||||
@ -1021,6 +1041,7 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
|
||||
JS_SetPropertyStr(context, object, "messageContentGet", JS_NewCFunction(context, _tf_ssb_messageContentGet, "messageContentGet", 1));
|
||||
JS_SetPropertyStr(context, object, "connections", JS_NewCFunction(context, _tf_ssb_connections, "connections", 0));
|
||||
JS_SetPropertyStr(context, object, "getConnection", JS_NewCFunction(context, _tf_ssb_getConnection, "getConnection", 1));
|
||||
JS_SetPropertyStr(context, object, "closeConnection", JS_NewCFunction(context, _tf_ssb_closeConnection, "closeConnection", 1));
|
||||
JS_SetPropertyStr(context, object, "sqlStream", JS_NewCFunction(context, _tf_ssb_sqlStream, "sqlStream", 3));
|
||||
JS_SetPropertyStr(context, object, "storeMessage", JS_NewCFunction(context, _tf_ssb_storeMessage, "storeMessage", 1));
|
||||
JS_SetPropertyStr(context, object, "getBroadcasts", JS_NewCFunction(context, _tf_ssb_getBroadcasts, "getBroadcasts", 0));
|
||||
|
Reference in New Issue
Block a user