From 78008e99048fdf51f545368419166a02c8ff1355 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 22 Sep 2008 16:09:10 -0500 Subject: [PATCH] Better connection logging --- basis/io/servers/connection/connection.factor | 14 ++++++++++---- basis/io/sockets/secure/secure.factor | 4 +++- basis/io/sockets/sockets.factor | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/basis/io/servers/connection/connection.factor b/basis/io/servers/connection/connection.factor index 7d72659f6d..1b8707fc8c 100755 --- a/basis/io/servers/connection/connection.factor +++ b/basis/io/servers/connection/connection.factor @@ -2,10 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. USING: continuations destructors kernel math math.parser namespaces parser sequences strings prettyprint debugger -quotations combinators logging calendar assocs +quotations combinators logging calendar assocs present fry accessors arrays io io.sockets io.encodings.ascii io.sockets.secure io.files io.streams.duplex io.timeouts -io.encodings threads concurrency.combinators +io.encodings threads make concurrency.combinators concurrency.semaphores concurrency.flags combinators.short-circuit ; IN: io.servers.connection @@ -56,11 +56,17 @@ GENERIC: handle-client* ( threaded-server -- ) [ secure>> >secure ] [ insecure>> >insecure ] bi [ resolve-host ] bi@ append ; -LOG: accepted-connection NOTICE +: accepted-connection ( remote local -- ) + [ + [ "remote: " % present % ", " % ] + [ "local: " % present % ] + bi* + ] "" make + \ accepted-connection NOTICE log-message ; : log-connection ( remote local -- ) + [ accepted-connection ] [ [ remote-address set ] [ local-address set ] bi* ] - [ 2array accepted-connection ] 2bi ; M: threaded-server handle-client* handler>> call ; diff --git a/basis/io/sockets/secure/secure.factor b/basis/io/sockets/secure/secure.factor index 3e516dff8b..42ca727653 100755 --- a/basis/io/sockets/secure/secure.factor +++ b/basis/io/sockets/secure/secure.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel symbols namespaces continuations destructors io.sockets sequences summary calendar delegate -system vocabs.loader combinators ; +system vocabs.loader combinators present ; IN: io.sockets.secure SYMBOL: secure-socket-timeout @@ -43,6 +43,8 @@ TUPLE: secure addrspec ; C: secure +M: secure present addrspec>> present " (secure)" append ; + CONSULT: inet secure addrspec>> ; M: secure resolve-host ( secure -- seq ) diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index 8c9f26b1dd..9bfcc7e310 100755 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -5,8 +5,8 @@ USING: generic kernel io.backend namespaces continuations sequences arrays io.encodings io.ports io.streams.duplex io.encodings.ascii alien.strings io.binary accessors destructors classes debugger byte-arrays system combinators parser -alien.c-types math.parser splitting grouping -math assocs summary system vocabs.loader combinators ; +alien.c-types math.parser splitting grouping math assocs summary +system vocabs.loader combinators present ; IN: io.sockets << { @@ -40,7 +40,14 @@ TUPLE: local path ; : ( path -- addrspec ) normalize-path local boa ; -TUPLE: inet4 host port ; +M: local present path>> "Unix domain socket: " prepend ; + +TUPLE: abstract-inet host port ; + +M: abstract-inet present + [ host>> ":" ] [ port>> number>string ] bi 3append ; + +TUPLE: inet4 < abstract-inet ; C: inet4 @@ -81,7 +88,7 @@ M: inet4 parse-sockaddr >r dup sockaddr-in-addr r> inet-ntop swap sockaddr-in-port ntohs ; -TUPLE: inet6 host port ; +TUPLE: inet6 < abstract-inet ; C: inet6 @@ -255,7 +262,7 @@ HOOK: addrinfo-error io-backend ( n -- ) GENERIC: resolve-host ( addrspec -- seq ) -TUPLE: inet host port ; +TUPLE: inet < abstract-inet ; C: inet