Re: [AOLSERVER] ns_socklistencallback

2002-11-28 Thread Zoran Vasiljevic
On Thursday 28 November 2002 07:58, you wrote:


  From what I've tested, it looks like ns_thread begindetached actually
 grabs available threads from the pool... So using thread 2.5 (once Zoran
 gets it done) to implement thread pools inside AOLserver would be like
 reinventing the wheel.


I will try to get the Tcl thread 2.5 extension for Tcl
(and AOLserver) done until end of the year.
It will include the threadpool implementation in both
Tcl and C, a nice abstraction of threads and nsv_* like
interface for shared variables with much larger command
set and internal shared-object handling.
The channel-passing feature (for Tcl8.4+) with both
channel transfer and channel detach/attach functionality
between threads is also included.

The key feature of threadpool implementation is that is
entirely event-loop aware, so application written with
event-loop style wont be blocked while waiting on the
free pool worker or waiting to collect the result of
the posted job. I hope this will simplify much of the
code written initialy with event-loop style and being
ported to the threads paradigm.

The extension will also include an example of a tiny
MT-enabled web-server and general purpose command-line
server, all done in 100-300 lines of Tcl.

Cheers
Zoran



Re: [AOLSERVER] ns_socklistencallback

2002-11-28 Thread Tom Jackson
Wojciech Kocjan wrote:

  One pool is for
  worker threads, and one (with one thread) serialized access to a single
  fd. You have multiple fds, so you probably don't need the second pool.

 Actually, why the second pool? I once used a master thread and slave
 threads.

I used a second pool (of 1 thread) so that the worker threads could
queue the packets they needed to send out the single fd.

--Tom Jackson



Re: [AOLSERVER] ns_socklistencallback

2002-11-27 Thread David Walker
Thanks Scott.

Guess I expected too much from this command.  Apparently it can only accept
one connection at a time.

On Sunday 24 November 2002 01:50 pm, Scott S. Goodwin wrote:
 Here's a piece of test code I've used in the past:

 # This proc is run when a connection occurs

 proc handle_socklistencallback {rfd wfd} {
 ns_log notice A client has connected to the socket
 while {[set line [string trim [gets $rfd]]] != } {
 lappend headers $line
 }
 ns_log notice CLIENT HTTP HEADERS:
 ns_log notice $headers

 set content_htm \
 html
 head
 titlenon-ssl test/title
 /head
 body
 pGreat! We were able to do a listen-callback on a socket,
 read the client HTTP header and send back this HTML page. Hit the back
 button to return to the test page.
 pHere ar the HTTP client headers you sent me:
 p$headers
 /body
 /html

 set myheader \
 HTTP/1.0 200 Document follows
 MIME-Version: 1.0
 Content-Type: text/html
 Content-Length: [string length $content_htm]

 puts $wfd \
 $myheader


 $content_htm

 flush $wfd
 close $rfd
 close $wfd
 }

 # This starts the listener on an address and port, and tells it
 # what proc to run when a connection comes in

 ns_socklistencallback 192.168.0.2 8443 handle_socklistencallback


 /s.

 ---
 Scott S. Goodwin
 e: [EMAIL PROTECTED] | u: http://scottg.net
 aim: scottgnet


 - Original Message -
 From: David Walker [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Sunday, November 24, 2002 10:23 AM
 Subject: [AOLSERVER] ns_socklistencallback

  does anyone have any ns_socklistencallback sample code?



Re: [AOLSERVER] ns_socklistencallback

2002-11-27 Thread Scott S. Goodwin
Yes, but you should be able to code it to push any conns into another thread
and let the listener go back to listening. Tell us what your reqt is and
we'll see if we can come up with a way to make it work.

/s.

---
Scott S. Goodwin
e: [EMAIL PROTECTED] | u: http://scottg.net
aim: scottgnet

- Original Message -
From: David Walker [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, November 27, 2002 2:15 PM
Subject: Re: [AOLSERVER] ns_socklistencallback


 Thanks Scott.

 Guess I expected too much from this command.  Apparently it can only
accept
 one connection at a time.

 On Sunday 24 November 2002 01:50 pm, Scott S. Goodwin wrote:
  Here's a piece of test code I've used in the past:
 
  # This proc is run when a connection occurs
 
  proc handle_socklistencallback {rfd wfd} {
  ns_log notice A client has connected to the socket
  while {[set line [string trim [gets $rfd]]] != } {
  lappend headers $line
  }
  ns_log notice CLIENT HTTP HEADERS:
  ns_log notice $headers
 
  set content_htm \
  html
  head
  titlenon-ssl test/title
  /head
  body
  pGreat! We were able to do a listen-callback on a socket,
  read the client HTTP header and send back this HTML page. Hit the back
  button to return to the test page.
  pHere ar the HTTP client headers you sent me:
  p$headers
  /body
  /html
 
  set myheader \
  HTTP/1.0 200 Document follows
  MIME-Version: 1.0
  Content-Type: text/html
  Content-Length: [string length $content_htm]
 
  puts $wfd \
  $myheader
 
 
  $content_htm
 
  flush $wfd
  close $rfd
  close $wfd
  }
 
  # This starts the listener on an address and port, and tells it
  # what proc to run when a connection comes in
 
  ns_socklistencallback 192.168.0.2 8443 handle_socklistencallback
 
 
  /s.
 
  ---
  Scott S. Goodwin
  e: [EMAIL PROTECTED] | u: http://scottg.net
  aim: scottgnet
 
 
  - Original Message -
  From: David Walker [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Sunday, November 24, 2002 10:23 AM
  Subject: [AOLSERVER] ns_socklistencallback
 
   does anyone have any ns_socklistencallback sample code?





Re: [AOLSERVER] ns_socklistencallback

2002-11-27 Thread Tom Jackson
David Walker wrote:


I want to support a reasonable number of concurrent connections.  I am running
a tcl based SMTP filter/server based on the smtpd in tcllib.  I am converting
it to run within AOLServer.

Can ns_socklistencallback push the conn to another thread or will I have to
use ns_socklisten, ns_sockaccept, and ns_thread?


I thought that ns_socklistencallback provided a separate thread for each
connection, maybe that isn't true, but it should still be able to handle
multiple connections at the same time. Did you do testing that indicated
otherwise?
If you really need separate processing threads, I have used two
threadpools, using Rob Mayoff's dqd_threadpool module. One pool is for
worker threads, and one (with one thread) serialized access to a single
fd. You have multiple fds, so you probably don't need the second pool.
I hope, someday, we will have a module that generalizes the ns_conn
module: allowing optional url support, but not specific to the http
protocol. For lack of a better name I'm using ns_tcp and ns_udp. So the
day someone invents the next great protocol, AOLserver will be the
programming environment of choice.

--Tom Jackson



Re: [AOLSERVER] ns_socklistencallback

2002-11-27 Thread David Walker
I like the ns_tcp and ns_udp ideas.
I have the idea that since most protocols are about the same that I should be
able to do about anything from aolserver/tcl

Here's my test so you can look it over.

proc handle_socklistencallback {rfd wfd} {
set headers {}
puts $wfd {welcome}
flush $wfd
gets $rfd cmdline
close $rfd
close $wfd
}

ns_socklistencallback * 8443 handle_socklistencallback

telnet machinename 8443 from 2 different machines.
The first one gets welcome
The second one accepts the connection but doesn't get wecome until the first
connection ends.


On Wednesday 27 November 2002 05:59 pm, (Via wrote:
 David Walker wrote:
 I want to support a reasonable number of concurrent connections.  I am
  running a tcl based SMTP filter/server based on the smtpd in tcllib.  I
  am converting it to run within AOLServer.
 
 Can ns_socklistencallback push the conn to another thread or will I have
  to use ns_socklisten, ns_sockaccept, and ns_thread?

 I thought that ns_socklistencallback provided a separate thread for each
 connection, maybe that isn't true, but it should still be able to handle
 multiple connections at the same time. Did you do testing that indicated
 otherwise?
 If you really need separate processing threads, I have used two
 threadpools, using Rob Mayoff's dqd_threadpool module. One pool is for
 worker threads, and one (with one thread) serialized access to a single
 fd. You have multiple fds, so you probably don't need the second pool.
 I hope, someday, we will have a module that generalizes the ns_conn
 module: allowing optional url support, but not specific to the http
 protocol. For lack of a better name I'm using ns_tcp and ns_udp. So the
 day someone invents the next great protocol, AOLserver will be the
 programming environment of choice.

 --Tom Jackson



Re: [AOLSERVER] ns_socklistencallback

2002-11-27 Thread Tom Jackson
It looks like ns_socklistencallback closes the socket when the proc
returns.
I tried the following code:

proc echo_server {fdString} {

ns_log notice A client has connected to the socket at [ns_time]
set fdList [split $fdString ,]
set rfd [lindex $fdList 0]
set wfd [lindex $fdList 1]
while {[set line [string trim [gets $rfd]]] != } {
puts $wfd $line
flush $wfd
}

close $rfd
close $wfd
}


proc echo_server_improved {rfd wfd} {

ns_log Notice Client connecting to improved echo server
ns_schedule_proc -once -thread 0 echo_server ${rfd},${wfd}
}


ns_socklistencallback 216.254.26.186  echo_server_improved


But I got the following error:

[27/Nov/2002:16:36:23][2682.3076][-socks-] Notice: Client connecting to
improved echo server
[27/Nov/2002:16:36:23][2682.5126][-sched:19-] Notice: A client has
connected to the socket at 1038443783
[27/Nov/2002:16:36:23][2682.5126][-sched:19-] Error: can not find
channel named sock6

So it looks useless for your intended purpose, at least using a
scheduled proc.

--Tom Jackson



Re: [AOLSERVER] ns_socklistencallback

2002-11-27 Thread Tom Jackson
David Walker wrote:

 I like the ns_tcp and ns_udp ideas.
 I have the idea that since most protocols are about the same that I should be
 able to do about anything from aolserver/tcl

 Here's my test so you can look it over.

 proc handle_socklistencallback {rfd wfd} {
 set headers {}
 puts $wfd {welcome}
 flush $wfd
 gets $rfd cmdline
 close $rfd
 close $wfd
 }

 ns_socklistencallback * 8443 handle_socklistencallback

 telnet machinename 8443 from 2 different machines.
 The first one gets welcome
 The second one accepts the connection but doesn't get wecome until the first
 connection ends.

That's what I get if you use my echo_server. Connections are accepted,
but obviously everything is blocking waiting on the first connection to
finish.

--Tom Jackson



Re: [AOLSERVER] ns_socklistencallback

2002-11-27 Thread Dossy
On 2002.11.27, David Walker [EMAIL PROTECTED] wrote:
 Can ns_socklistencallback push the conn to another thread or will I have to
 use ns_socklisten, ns_sockaccept, and ns_thread?

I just tried ns_socklisten/ns_sockaccept/ns_thread begindetached ...
that won't work either.  Can't pass fd's between threads, it seems.

Look for one of Rob Mayoff's neato utilities that lets you detach a
socket fd or somesuch.  That way, you could push the fd's from the
master thread to the slave thread.

-- Dossy

--
Dossy Shiobara   mail: [EMAIL PROTECTED]
Panoptic Computer Network web: http://www.panoptic.com/
  He realized the fastest way to change is to laugh at your own
folly -- then you can let go and quickly move on. (p. 70)



Re: [AOLSERVER] ns_socklistencallback

2002-11-27 Thread Wojciech Kocjan
Tom Jackson wrote:

David Walker wrote:


I want to support a reasonable number of concurrent connections.  I am
running
a tcl based SMTP filter/server based on the smtpd in tcllib.  I am
converting
it to run within AOLServer.

Can ns_socklistencallback push the conn to another thread or will I
have to
use ns_socklisten, ns_sockaccept, and ns_thread?


I thought that ns_socklistencallback provided a separate thread for each
connection, maybe that isn't true, but it should still be able to handle
multiple connections at the same time. Did you do testing that indicated
otherwise?


It does not unless you patch it. I have my AOLserver (3.4.2-dq4) patched
against that (and switched Tcl to 8.3.4). It is available from
www.dq-e.com/aolserver/ in case somebody's interested.


If you really need separate processing threads, I have used two
threadpools, using Rob Mayoff's dqd_threadpool module.


From what I've tested, it looks like ns_thread begindetached actually
grabs available threads from the pool... So using thread 2.5 (once Zoran
gets it done) to implement thread pools inside AOLserver would be like
reinventing the wheel.

I even tested it with gdb+nscp:
dq:nscp 1 time {ns_thread begindetached {ns_sleep 1}; ns_sleep 2} 10

And gdb running 'dq' AOLserver did not notice any new threads.

The thing I miss most, however, is that there is no SSL equivalent that
would be creating threads on every accepted connection.


One pool is for
worker threads, and one (with one thread) serialized access to a single
fd. You have multiple fds, so you probably don't need the second pool.


Actually, why the second pool? I once used a master thread and slave
threads.


I hope, someday, we will have a module that generalizes the ns_conn
module: allowing optional url support, but not specific to the http
protocol. For lack of a better name I'm using ns_tcp and ns_udp. So the
day someone invents the next great protocol, AOLserver will be the
programming environment of choice.


Dream on ;-)

--
WK
(written at Stardate 56909.3)

Data typing is an illusion. Everything is a sequence of bytes.
 -Todd Coram



Re: [AOLSERVER] ns_socklistencallback

2002-11-24 Thread Scott S. Goodwin



Here's a piece of test code I've used in 
the past:
# This proc is run when a connection occurs

proc handle_socklistencallback {rfd wfd} 
{ ns_log notice "A client has connected to the 
socket" while {[set line [string trim [gets $rfd]]] != ""} 
{ lappend headers 
$line } ns_log notice "CLIENT HTTP 
HEADERS:" ns_log notice "$headers"

 set content_htm 
\"htmlheadtitlenon-ssl 
test/title/headbodypGreat! We were 
able to do a listen-callback on a socket,read the client HTTP header and 
send back this HTML page. Hit the backbutton to return to the test 
page.pHere ar the HTTP client headers you sent 
me:p$headers/body/html"

 set myheader 
\ "HTTP/1.0 200 Document 
followsMIME-Version: 1.0Content-Type: text/htmlContent-Length: 
[string length $content_htm]"

 puts $wfd 
\"$myheader

$content_htm"

 flush 
$wfd close $rfd close 
$wfd}

# This starts the listener on an address 
and port, and tells it
# what proc to run when a connection comes 
in

ns_socklistencallback192.168.0.2 8443 
handle_socklistencallback


/s.

---Scott 
S. Goodwine: [EMAIL PROTECTED] | u: http://scottg.netaim: 
scottgnet

- Original Message - 
From: "David Walker" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, November 24, 2002 10:23 
AM
Subject: [AOLSERVER] 
ns_socklistencallback
 does anyone have any ns_socklistencallback sample code?