clang-format the source. Not exactly how I want it, but automated is better than perfect.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4845 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-02-15 23:35:01 +00:00
parent c8812b1add
commit fbc3cfeda4
37 changed files with 3141 additions and 1764 deletions

View File

@ -22,13 +22,15 @@ static tf_tls_context_t* _defaultTlsContext;
static socket_t** _sockets;
static int _sockets_count;
typedef enum _socket_direction_t {
typedef enum _socket_direction_t
{
kUndetermined,
kAccept,
kConnect,
} socket_direction_t;
typedef struct _socket_t {
typedef struct _socket_t
{
tf_task_t* _task;
uv_tcp_t _socket;
uv_timer_t _timer;
@ -51,7 +53,7 @@ typedef struct _socket_t {
} socket_t;
static JSValue _socket_create(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static void _socket_finalizer(JSRuntime *runtime, JSValue value);
static void _socket_finalizer(JSRuntime* runtime, JSValue value);
static JSValue _socket_startTls(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
static JSValue _socket_stopTls(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
@ -131,8 +133,7 @@ static void _socket_gc_mark(JSRuntime* runtime, JSValueConst value, JS_MarkFunc
JSValue tf_socket_register(JSContext* context)
{
JS_NewClassID(&_classId);
JSClassDef def =
{
JSClassDef def = {
.class_name = "Socket",
.finalizer = &_socket_finalizer,
.gc_mark = _socket_gc_mark,
@ -158,7 +159,8 @@ int tf_socket_get_open_count()
return _open_count;
}
typedef struct _socket_resolve_data_t {
typedef struct _socket_resolve_data_t
{
uv_getaddrinfo_t resolver;
socket_t* socket;
promiseid_t promise;
@ -241,20 +243,16 @@ static void _socket_close_internal(socket_t* socket)
tf_tls_session_destroy(socket->_tls);
socket->_tls = NULL;
}
if (socket->_socket.data &&
!uv_is_closing((uv_handle_t*)&socket->_socket))
if (socket->_socket.data && !uv_is_closing((uv_handle_t*)&socket->_socket))
{
uv_close((uv_handle_t*)&socket->_socket, _socket_onClose);
}
if (socket->_timer.data &&
!uv_is_closing((uv_handle_t*)&socket->_timer))
if (socket->_timer.data && !uv_is_closing((uv_handle_t*)&socket->_timer))
{
uv_close((uv_handle_t*)&socket->_timer, _socket_onClose);
}
if (!socket->_socket.data &&
!socket->_timer.data &&
JS_IsUndefined(socket->_object))
if (!socket->_socket.data && !socket->_timer.data && JS_IsUndefined(socket->_object))
{
--_count;
for (int i = 0; i < _sockets_count; i++)
@ -282,7 +280,7 @@ static void _socket_reportError(socket_t* socket, const char* error)
{
JSContext* context = tf_task_get_context(socket->_task);
JSValue ref = JS_DupValue(context, socket->_object);
if (JS_IsFunction(context, socket-> _onError))
if (JS_IsFunction(context, socket->_onError))
{
JSValue exception = JS_ThrowInternalError(context, "%s", error);
JSValue cb_ref = JS_DupValue(context, socket->_onError);
@ -393,8 +391,7 @@ static bool _socket_processSomeOutgoingTls(socket_t* socket, promiseid_t promise
char* rawBuffer = request_buffer + sizeof(uv_write_t);
memcpy(rawBuffer, buffer, result);
uv_buf_t writeBuffer =
{
uv_buf_t writeBuffer = {
.base = rawBuffer,
.len = result,
};
@ -431,8 +428,7 @@ static JSValue _socket_bind(JSContext* context, JSValueConst this_val, int argc,
socket_resolve_data_t* data = tf_malloc(sizeof(socket_resolve_data_t));
memset(data, 0, sizeof(*data));
struct addrinfo hints =
{
struct addrinfo hints = {
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
.ai_protocol = IPPROTO_TCP,
@ -455,14 +451,16 @@ static void _socket_onResolvedForBind(uv_getaddrinfo_t* resolver, int status, st
socket_resolve_data_t* data = (socket_resolve_data_t*)resolver->data;
if (status != 0)
{
tf_task_reject_promise(data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_getaddrinfo: %s", uv_strerror(status)));
tf_task_reject_promise(
data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_getaddrinfo: %s", uv_strerror(status)));
}
else
{
int bindResult = uv_tcp_bind(&data->socket->_socket, result->ai_addr, 0);
if (bindResult != 0)
{
tf_task_reject_promise(data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_tcp_bind: %s", uv_strerror(bindResult)));
tf_task_reject_promise(
data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_tcp_bind: %s", uv_strerror(bindResult)));
}
else
{
@ -642,9 +640,7 @@ static JSValue _socket_accept(JSContext* context, JSValueConst this_val, int arg
static JSValue _socket_close(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
{
socket_t* socket = JS_GetOpaque(this_val, _classId);
if (socket->_closePromise == -1 &&
socket->_socket.data &&
!uv_is_closing((uv_handle_t*)&socket->_socket))
if (socket->_closePromise == -1 && socket->_socket.data && !uv_is_closing((uv_handle_t*)&socket->_socket))
{
JSValue result = tf_task_allocate_promise(socket->_task, &socket->_closePromise);
_socket_close_internal(socket);
@ -921,8 +917,7 @@ static int _socket_writeInternal(socket_t* socket, promiseid_t promise, const ch
uv_write_t* request = (uv_write_t*)rawBuffer;
memcpy(rawBuffer + sizeof(uv_write_t), data, length);
uv_buf_t buffer =
{
uv_buf_t buffer = {
.base = rawBuffer + sizeof(uv_write_t),
.len = length,
};
@ -1018,11 +1013,13 @@ static JSValue _socket_setActivityTimeout(JSContext* context, JSValueConst this_
{
socket_t* socket = JS_GetOpaque(this_val, _classId);
int64_t timeout = 0;
if (JS_ToInt64(context, &timeout, argv[0]) == 0 &&
socket->timeout_ms > 0) {
if (JS_ToInt64(context, &timeout, argv[0]) == 0 && socket->timeout_ms > 0)
{
socket->timeout_ms = timeout;
uv_timer_start(&socket->_timer, _socket_timeout, socket->timeout_ms, 0);
} else {
}
else
{
uv_timer_stop(&socket->_timer);
}
return JS_UNDEFINED;