Opening Win32 pipe strange behaviour

Started by pjot, July 14, 2004, 03:24:32 AM

Previous topic - Next topic

Lutz

#15
Are there any runtimes libraries to install (like on the CYGWIN version of newLISP) ?



Lutz

pjot

#16
No extra DLL's needed. The nice thing of MinGW is, that you do not an external DLL to run your program, as is the case with Cygwin. Actually, this was the reason why the MinGW project was started. The MinGW compiler tries to link with msvcrt.dll. Therefore, MinGW compiled binaries can run standalone without any additional libraries.



You can find the MinGW package at http://www.mingw.org">http://www.mingw.org



The only thing needed to install is the MinGW-3.1.0-1.exe package. This package contains all include files and object files.

Lutz

#17
what about the msys, gcc, binutils, make packages. Are they really not required?



Lutz

pjot

#18
Yeah you are right, the MSYS package is needed to simulate a SHELL environment.



The other packages are not necessary; they are development packages which can be installed separately.



If you install the MinGW package and the MSYS package, this *should* be enough to make a compilation. Unless you insist on compiling with GCC3.4.0??



First install MinGW, after that the MSYS shell. Then you're all set.

Lutz

#19
thanks, started the first compile, looks much better this time around



lutz

pjot

#20
I've tested the following with Borland:



----------------------------------------

#include <windows.h>

#include <stdio.h>

#include <process.h>

#include <io.h>

#include <fcntl.h>

#include <sys/stat.h>



int main() {



int n;

HANDLE hPipe;



printf("Connecting to PIPE 'out'...n");

if ((n = open ("\\.\pipe\out", O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE)) < 0){

   printf("Open FAILED!n");

   exit(-1);

}

else printf("Filehandle is: %dn", n);



printf("Connecting to PIPE 'in'...n");

hPipe = CreateFile(

         "\\.\pipe\in",

         GENERIC_READ,

         0,

         NULL,

         OPEN_EXISTING,

         0,

         NULL);

 

if (hPipe == INVALID_HANDLE_VALUE){

   printf("Open FAILED!n");

   exit(-1);

}

else printf("Filehandle is: %dn", (int)hPipe);



printf("All pipes can connect!n");



return 0;

}

----------------------------------------



So for the READ_ONLY part, I use the CreateFile function. When compiling with Borland, this works OK; I can connect to the Named Pipe of the GTK-server:



C:Gtk-serverGtk1>pipe

Connecting to PIPE 'out'...

Filehandle is: 3

Connecting to PIPE 'in'...

Filehandle is: 1996

All pipes can connect!



If you use the __BORLAND__ macro anyway, maybe it is an idea to change only the "open" "r" part using the CreateFile function surrounded by the __BORLAND__ macro? The first argument of CreateFile points to the file/directory/mailslot/pipe.



I guess this will save you a lot of time instead of testing and recompiling the whole newLisp with MinGW.

Lutz

#21
Thanks for investigating this. I might go MinGW anyway, don't know yet. In the long run MinGW is probably the better solution as all it's tools are GNU based and the same tools used in the Linux/UNIX versions, they will probably converge more and more, while with a proprietary product like Borland, you don't even know how long it will exists. I have some 'emotional' bonds to that BCC compiler, because I worked there for a while (Quatro Pro 6.0, non-US international versions).



If the MinGW port gets too tough I will go with the Win32 CreateFile() solution, and try again 1/2 year later with MinGW. They seem to get closer and closer to be 100% compatible with GNU on Linux/UNIX.



Lutz

adamss3

#22
I'd vote for staying with the Borland compiler for ease of changes.  Last time, therre were a number of changes that would need to be done to move to MinGW.

Lutz

#23
Turns out that the latest MinGW-3.1.0-1 is pretty close to Borland BCC in required changes. With little differences it can use the same #ifdef's. The only mayor thing was the return value of vsnprintf() and the naming of FILE structure members.



I have posted a newlisp-mingw.exe in the http://newlisp.org/downloads/development">http://newlisp.org/downloads/development directory perhaps Pjot can tell us if it works with named pipes on the GTK-Server. I did not much test it, so expect everything :)



newlisp-mingw.exe is about 25% bigger than the executable generated with Borland BCC and I could reduce this a tiny bit by changing the optimization options.



For now I will stay with BCC for the binary Win32 distribution but include a new makefile_mingw in the source distribution for people who want to compile with MinGW, whch definetly has advanced quite a bit during the last year or so and is an OSS alternative to Borland BCC.



Still, I think that CYGWIN does the best Win32 solution if it comes to source code compatibility with Linux. This is because they can hide all differences in the addtional libraries, which have to be installed. Borland and MinGW depend solely on the runtime libraries installed by Wndows.



Lutz

pjot

#24
That's cool! I'll try it immediately, and let you know the results. Thanx!!



Strange that the resulting binary is bigger than the Borland version. In almost all my programs I experience the other way around...

pjot

#25
Hi Lutz!



Well, good news: it works!! See the GTK-server demo program below. With the Borland-binary this program will not run.



But for some strange reason, the (sleep x) function does not work anymore with the MinGW binary, so I simulated a sleep with a large (for) loop.



Anyway, I volunteer to test the MinGW version of newLisp in the next future. If you are OK, I will use it in all my Win32 newLisp programs and submit problems to this forum...? (So one problem already is the 'sleep' function... ;0) )



Thank you for the extremely good and fast support.



Regards



Peter



============================



;------------------------------------------------

;

; Demonstration on how to use the GTK-server with NEWLISP by FIFO.

; Tested with newLISP 8.0.9 compiled with MinGW on WindowsXP.

;

; July 17, 2004 by Pjot.

;

;------------------------------------------------



; Define communication function

(define (gtk str)

(write-buffer pipeout str)

(read-buffer pipein 'tmp 128)

tmp)



; Start the gtk-server

(process "gtk-server fifo log")

(for (x 1 2000000))



; Connect to the GTK-server

(set 'pipeout (open {\.pipeout} "w"))

(println pipeout)

(set 'pipein (open {\.pipein} "r"))

(println pipein)



; Setup GUI

(gtk "gtk_init(NULL, NULL)")

(set 'win (gtk "gtk_window_new(0)"))

(gtk (append "gtk_window_set_title (" win ", This is a title)"))

(gtk (append "gtk_window_set_default_size (" win ", 100, 100)"))

(gtk (append "gtk_window_set_position (" win ", 1 )"))

(set 'table (gtk "gtk_table_new(30, 30, 1 )"))

(gtk (append "gtk_container_add (" win "," table ")"))

(set 'button1 (gtk "gtk_button_new_with_label (Exit)"))

(gtk (append "gtk_table_attach_defaults(" table ", " button1 ", 17, 28, 20, 25)"))

(set 'button2 (gtk "gtk_button_new_with_label (Print text)"))

(gtk (append "gtk_table_attach_defaults (" table ", " button2 ", 2, 13, 20, 25)"))

(set 'entry (gtk "gtk_entry_new()"))

(gtk (append "gtk_table_attach_defaults (" table ", " entry ", 2, 28, 5, 15)"))

(gtk (append "gtk_widget_show_all(" win ")"))

(gtk (append "gtk_widget_grab_focus(" entry ")"))



; Initialize

(set 'cb1 0)

(set 'cb2 0)

(set 'event 0)



; This is the mainloop

(while (= (integer event) 0)

   (gtk "gtk_main_iteration_do(0)")

   (set 'cb1 (gtk (append "gtk_server_callback(" button2 ")")))

   (set 'cb2 (gtk (append "gtk_server_callback(" entry ")")))

   (if (or (= (integer cb1) 1) (= (integer cb2) 1))

      (begin

         (set 'tmp (gtk (append "gtk_entry_get_text(" entry ")")))

         (println tmp)

         (gtk (append "gtk_editable_delete_text(" entry ", 0, -1)"))

         (gtk (append "gtk_widget_grab_focus(" entry ")"))

      ))

   (set 'event (gtk (append "gtk_server_callback(" button1 ")"))))



(write-buffer pipeout "gtk_exit(0)")

(exit)

adamss3

#26
It might be that we need to define another conditional compiler point in the p_sleep routine to call the Win32 Sleep() function  (in Kernel32.dll).  That should fix the sleep problem.

Lutz

#27
Good News! Turns out I was linking unnecessary libraries. The new version of newlisp-mingw.exe is only 143Kbyte, that is a similar size as on Linux and BSD. I also could fix the 'sleep' error.



I have replaced the newlisp-mingw.exe with the smaller one with the sleep fix on the usual http://newlisp.org/downloads/development/">http://newlisp.org/downloads/development/



We will have a new development release with an improved 'net-sessions' during the coming week.



Thanks for doing more testing. I am very encouraged now with the smaller size of the exe file and might consider to make MinGW the default for the Win32 distribution.



Lutz

pjot

#28
Perfect.



With this new binary everything in the demoprogram works. I have replaced the (for) for a (sleep 1000). I have also put the final demoscript for newLisp with Win32 Named Pipes at my site http://www.gtk-server.org">http://www.gtk-server.org



NewLisp is the first non-basic language to support named pipes in Win32 with the GTK-server. The advantage is obvious: TCP ports will remain available for real network applications. Named Pipe support for Linux already worked.



Lutz, thanks again for your efforts. And I am happy to know that you are considering MinGW as your default compiler! I will use the MinGW port from now on myself, and let you know about difficulties or strange behaviour.



Thanks!



Peter

HPW

#29
>I am very encouraged now with the smaller size of the exe file and might consider to make MinGW the default for the Win32 distribution.



Will then the DLL also compiled with MinGW?

Will the size reduced about the same size?
Hans-Peter