+}
+
+proc sendownping {} {
+ global ownping_every nick
+ sendout ping $nick
+ after $ownping_every sendownping
+}
+
+proc msg_001 {args} {
+ global muststartby_after
+ if {[info exists muststartby_after]} {
+ after cancel $muststartby_after
+ unset muststartby_after
+ sendownping
+ connected
+ }
+}
+
+proc ensure_outqueue {} {
+ out__vars
+ if {[info exists out_queue]} return
+ set out_creditms 0
+ set out_creditat [clock seconds]
+ set out_queue {}
+ set out_lag_reported 0
+ set out_lag_reportwhen $out_creditat
+}
+
+proc fail {msg} {
+ logerror "failing: $msg"
+ exit 1
+}
+
+proc ensure_connecting {} {
+ global sock ownfullname host port nick ident socketargs
+ global muststartby_ms muststartby_after
+
+ ensure_outqueue
+
+ if {[info exists sock]} return
+ set sock [eval socket $socketargs [list $host $port]]
+ fconfigure $sock -buffering line
+ fconfigure $sock -translation crlf
+
+ sendout USER $ident 0 * $ownfullname
+ sendout NICK $nick
+ fileevent $sock readable onread
+
+ set muststartby_after [after $muststartby_ms \
+ {fail "no successfuly connect within timeout"}]