Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
irker
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iDB
irker
Commits
d457b8ee
Commit
d457b8ee
authored
12 years ago
by
Eric S. Raymond
Browse files
Options
Downloads
Patches
Plain Diff
Clean up sessions when their sockets timee out.
parent
050927e4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
irker.py
+15
-4
15 additions, 4 deletions
irker.py
with
15 additions
and
4 deletions
irker.py
+
15
−
4
View file @
d457b8ee
...
...
@@ -13,7 +13,6 @@ Requires Python 2.6.
TO-DO: Is there any way to cope is servers drop connections?
TO-DO: Multiple irkers could try to use the same nick
TO-DO: time out session instances as well as sockets.
TO-DO: Register the port?
"""
# These things might need tuning
...
...
@@ -66,14 +65,15 @@ class Session():
# expires, then reconnect and resume transmission if the
# queue fills up again.
if
not
self
.
server
:
self
.
server
=
self
.
irker
.
allocate_server
(
self
.
servername
,
self
.
server
=
self
.
irker
.
open
(
self
.
servername
,
self
.
port
)
self
.
irker
.
debug
(
1
,
"
TTL bump (connection) at %s
"
%
time
.
asctime
())
self
.
last_active
=
time
.
time
()
elif
self
.
queue
.
empty
():
if
time
.
time
()
>
self
.
last_active
+
TTL
:
self
.
irker
.
debug
(
1
,
"
timing out inactive connection at %s
"
%
time
.
asctime
())
self
.
server
.
part
(
"
#
"
+
self
.
channel
)
self
.
irker
.
close
(
self
.
servername
,
self
.
port
)
self
.
server
=
None
break
else
:
...
...
@@ -83,6 +83,10 @@ class Session():
self
.
last_active
=
time
.
time
()
self
.
irker
.
debug
(
1
,
"
TTL bump (transmission) at %s
"
%
time
.
asctime
())
self
.
queue
.
task_done
()
def
terminate
(
self
):
"
Terminate this session
"
self
.
server
.
quit
(
"
#
"
+
self
.
channel
)
self
.
server
.
close
()
def
await
(
self
):
"
Block until processing of all queued messages is done.
"
self
.
queue
.
join
()
...
...
@@ -106,7 +110,7 @@ class Irker:
"
Debugging information.
"
if
self
.
debuglevel
>=
level
:
sys
.
stderr
.
write
(
"
irker[%d]: %s
\n
"
%
(
self
.
debuglevel
,
errmsg
))
def
allocate_server
(
self
,
servername
,
port
):
def
open
(
self
,
servername
,
port
):
"
Allocate a new server instance.
"
if
not
(
servername
,
port
)
in
self
.
countmap
:
self
.
countmap
[(
servername
,
port
)]
=
(
CONNECT_MAX
+
1
,
None
)
...
...
@@ -119,6 +123,13 @@ class Irker:
"
irker%03d
"
%
self
.
servercount
)
self
.
countmap
[(
servername
,
port
)]
=
(
1
,
newserver
)
return
self
.
countmap
[(
servername
,
port
)][
1
]
def
close
(
self
,
servername
,
port
):
"
Release a server instance and all sessions using it.
"
del
self
.
countmap
[(
servername
,
port
)]
for
(
key
,
val
)
in
self
.
sessions
:
if
(
val
.
servername
,
val
.
port
)
==
(
servername
,
port
):
self
.
sessions
[
servername
].
terminate
()
del
self
.
sessions
[
servername
]
def
handle
(
self
,
line
):
"
Perform a JSON relay request.
"
try
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment