This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Async socket waits untill ends

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Async socket waits untill ends

Post by Ofloo »

Code: Select all

#!/usr/bin/tclsh

proc open_sock {host port} {
   global done
   if {[catch {socket -async $host $port} sock]} {
      puts "Connection to $host:$port failed: $sock"
   } else {
      fileevent $sock writable [list check_sock $sock $host $port]
      vwait done($sock)
   }
}
proc check_sock {sock host port} {
   global done
   if {[fconfigure $sock -error]==""} {
      puts "Connected to $host:$port"
   } else {
      puts "Connection to $host:$port failed: [fconfigure $sock -error]"
   }
   close $sock
   set done($sock) 1
}
i am using an async socket in a while to connect to multiple targets at once but there appears to be no difference when i use a async socket or a regular one.. it waits untill the proc has ended .. why is this ?

i am using foreach ... to go true the process any suggestions to speed it up?
XplaiN but think of me as stupid
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Probably cos of the 'vwait done($sock)'
Once the game is over, the king and the pawn go back in the same box.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

well its required in a shell script otherwize the app would close ..
XplaiN but think of me as stupid
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Eggdrop won't exit when your script ends, so you don't need the vwait.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Async socket waits untill ends

Post by user »

Move the vwait to after your while loop? (remove it from the proc)
stdragon wrote:Eggdrop won't exit when your script ends, so you don't need the vwait.
I don't think he's running it in eggdrop's interpreter:
Ofloo wrote:

Code: Select all

#!/usr/bin/tclsh
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

where exactly cause ive tryed it and i got would wait forever and script breaks
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

and yes sorry hehe by shell i meanth shell script as in tclsh not as in eggdrop shell..
XplaiN but think of me as stupid
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Ofloo wrote:where exactly cause ive tryed it and i got would wait forever and script breaks
Try this:

Code: Select all

proc open_sock {host port} { 
	if {[catch {socket -async $host $port} sock]} {
		puts "Connection to $host:$port failed: $sock"
		return 0
	} else {
		fileevent $sock writable [list check_sock $sock $host $port] 
		return 1
	}
} 
proc check_sock {sock host port} { 
	global pending
	if {[fconfigure $sock -error]==""} { 
		puts "Connected to $host:$port" 
	} else { 
		puts "Connection to $host:$port failed: [fconfigure $sock -error]" 
	} 
	close $sock
	incr pending -1;
}

proc doit args {
	global pending
	set pending 0
	foreach {host port} $args {
		incr pending [open_sock $host $port]
	}
	while {$pending} {vwait pending}
	puts done.
}

doit localhost 22 localhost 23 localhost 25 localhost 110
Have you ever read "The Manual"?
Locked