a question about import. history library

Started by chylli, February 19, 2009, 02:12:58 AM

Previous topic - Next topic

chylli

hi, I'm a newbie of newlisp. now I writed one very simple mud client as following.



now it has two problem:

1. if I use readline search function, the program will exit silently. I think it is about memory problem.  can anyone fix it ???



2. when the peer of socket close the connection, the program will exit. but I must enter an "n" before the console returned to shell. why ?



thanks.



this is the probram:





#!/usr/bin/newlisp

;; server

(define mud-server '("pkuxkx.3322.org" 8081))



(context 'greadline)

(import "libhistory.so.5" "add_history")

(import "libreadline.so.5" "readline")

(define (greadline:greadline)

  (set 'getted-string-p (readline ""))

  (add_history getted-string-p)

  (get-string getted-string-p))



(context MAIN)



(set 'server (apply net-connect mud-server))



(fork (begin

        (while (net-receive server buffer 8192)

               (print buffer))

        (letn ((error (net-error))

               (error-code (error 0)))

          (if (= error-code 6)

              (println "bye bye!!")

              (print (error 1))))))



(constant 'SIGCHLD 17)

(define (sig_chld_handler)

  (wait-pid -1 nil)

  (close server)

  (exit))



(signal SIGCHLD sig_chld_handler)

 

(while 1 (net-send server (append (greadline) "rn")))





(exit)

Jeff

#1
For one thing, when you initialize with (readline ""), you are sending a string that is not anchored in memory. Assign "" to a local variable and then pass it to readline.



You exit early because you do (while (net-receive ...)).  For an example on how to loop a socket server indefinitely, take a look at my sockets module:



http://static.artfulcode.net/newlisp/sockets.lsp.html">http://static.artfulcode.net/newlisp/sockets.lsp.html
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

chylli

#2
my program exit early only when I use add_history function on libhistory. so I think I misused it ?



(while (net-recieve) ... is ok when I don't use add_history.  and it is a simplified version. I will change it when I resovled this problem.





thanks!