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
897be7c8
Commit
897be7c8
authored
12 years ago
by
Eric S. Raymond
Browse files
Options
Downloads
Patches
Plain Diff
Wrap library calls in a mutex for thread safety.
parent
8260dbe9
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
irkerd
+43
-32
43 additions, 32 deletions
irkerd
with
43 additions
and
32 deletions
irkerd
+
43
−
32
View file @
897be7c8
...
...
@@ -189,10 +189,11 @@ class Connection:
ping_timeout
=
now
>
self
.
last_ping
+
PING_TTL
if
(
xmit_timeout
or
ping_timeout
)
and
self
.
status
!=
"
disconnected
"
:
self
.
irker
.
debug
(
1
,
"
timing out connection to %s at %s (ping_timeout=%s, xmit_timeout=%s)
"
%
(
self
.
servername
,
time
.
asctime
(),
ping_timeout
,
xmit_timeout
))
self
.
connection
.
context
=
None
self
.
connection
.
quit
(
"
transmission timeout
"
)
self
.
connection
.
close
()
self
.
connection
=
None
with
self
.
irker
.
library_lock
:
self
.
connection
.
context
=
None
self
.
connection
.
quit
(
"
transmission timeout
"
)
self
.
connection
.
close
()
self
.
connection
=
None
self
.
status
=
"
disconnected
"
else
:
# Prevent this thread from hogging the CPU by pausing
...
...
@@ -203,23 +204,25 @@ class Connection:
time
.
sleep
(
ANTI_BUZZ_DELAY
)
elif
not
self
.
connection
:
# Queue is nonempty but server isn't connected.
self
.
connection
=
self
.
irker
.
irc
.
server
()
self
.
connection
.
context
=
self
# Try to avoid colliding with other instances
self
.
nick_trial
=
random
.
randint
(
1
,
990
)
self
.
channels_joined
=
{}
# This will throw irc.client.ServerConnectionError on failure
try
:
self
.
connection
.
connect
(
self
.
servername
,
self
.
port
,
nickname
=
self
.
nickname
(),
username
=
"
irker
"
,
ircname
=
"
irker relaying client
"
)
self
.
status
=
"
handshaking
"
self
.
irker
.
debug
(
1
,
"
XMIT_TTL bump (%s connection) at %s
"
%
(
self
.
servername
,
time
.
asctime
()))
self
.
last_xmit
=
time
.
time
()
except
irc
.
client
.
ServerConnectionError
:
self
.
status
=
"
disconnected
"
with
self
.
irker
.
library_lock
:
self
.
connection
=
self
.
irker
.
irc
.
server
()
self
.
connection
.
context
=
self
# Try to avoid colliding with other instances
self
.
nick_trial
=
random
.
randint
(
1
,
990
)
self
.
channels_joined
=
{}
try
:
# This will throw
# irc.client.ServerConnectionError on failure
self
.
connection
.
connect
(
self
.
servername
,
self
.
port
,
nickname
=
self
.
nickname
(),
username
=
"
irker
"
,
ircname
=
"
irker relaying client
"
)
self
.
status
=
"
handshaking
"
self
.
irker
.
debug
(
1
,
"
XMIT_TTL bump (%s connection) at %s
"
%
(
self
.
servername
,
time
.
asctime
()))
self
.
last_xmit
=
time
.
time
()
except
irc
.
client
.
ServerConnectionError
:
self
.
status
=
"
disconnected
"
elif
self
.
status
==
"
handshaking
"
:
if
time
.
time
()
>
self
.
last_xmit
+
HANDSHAKE_TTL
:
self
.
status
=
"
expired
"
...
...
@@ -245,16 +248,17 @@ class Connection:
self
.
status
=
"
expired
"
break
elif
self
.
status
==
"
ready
"
:
(
channel
,
message
)
=
self
.
queue
.
get
()
if
channel
not
in
self
.
channels_joined
:
self
.
connection
.
join
(
channel
)
self
.
irker
.
debug
(
1
,
"
joining %s on %s.
"
%
(
channel
,
self
.
servername
))
for
segment
in
message
.
split
(
"
\n
"
):
self
.
connection
.
privmsg
(
channel
,
segment
)
time
.
sleep
(
ANTI_FLOOD_DELAY
)
self
.
last_xmit
=
self
.
channels_joined
[
channel
]
=
time
.
time
()
self
.
irker
.
debug
(
1
,
"
XMIT_TTL bump (%s transmission) at %s
"
%
(
self
.
servername
,
time
.
asctime
()))
self
.
queue
.
task_done
()
with
self
.
irker
.
library_lock
:
(
channel
,
message
)
=
self
.
queue
.
get
()
if
channel
not
in
self
.
channels_joined
:
self
.
connection
.
join
(
channel
)
self
.
irker
.
debug
(
1
,
"
joining %s on %s.
"
%
(
channel
,
self
.
servername
))
for
segment
in
message
.
split
(
"
\n
"
):
self
.
connection
.
privmsg
(
channel
,
segment
)
time
.
sleep
(
ANTI_FLOOD_DELAY
)
self
.
last_xmit
=
self
.
channels_joined
[
channel
]
=
time
.
time
()
self
.
irker
.
debug
(
1
,
"
XMIT_TTL bump (%s transmission) at %s
"
%
(
self
.
servername
,
time
.
asctime
()))
self
.
queue
.
task_done
()
except
:
(
exc_type
,
_exc_value
,
exc_traceback
)
=
sys
.
exc_info
()
self
.
irker
.
logerr
(
"
exception %s in thread for %s
"
%
\
...
...
@@ -367,7 +371,8 @@ class Irker:
self
.
irc
.
add_global_handler
(
"
featurelist
"
,
self
.
_handle_features
)
self
.
irc
.
add_global_handler
(
"
disconnect
"
,
self
.
_handle_disconnect
)
self
.
irc
.
add_global_handler
(
"
kick
"
,
self
.
_handle_kick
)
thread
=
threading
.
Thread
(
target
=
self
.
irc
.
process_forever
)
self
.
library_lock
=
threading
.
Lock
()
thread
=
threading
.
Thread
(
target
=
self
.
_process_forever
)
thread
.
setDaemon
(
True
)
self
.
irc
.
_thread
=
thread
thread
.
start
()
...
...
@@ -379,6 +384,12 @@ class Irker:
"
Debugging information.
"
if
self
.
debuglevel
>=
level
:
sys
.
stderr
.
write
(
"
irkerd: %s
\n
"
%
errmsg
)
def
_process_forever
(
self
):
"
IRC library process_forever with mutex.
"
self
.
debug
(
1
,
"
process_forever()
"
)
while
True
:
with
self
.
library_lock
:
self
.
irc
.
process_once
()
def
_handle_ping
(
self
,
connection
,
_event
):
"
PING arrived, bump the last-received time for the connection.
"
if
connection
.
context
:
...
...
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