Hi Nigel,

You need select()! It's the best thing in the world (honest).

The following routine will check for activity on the socket "MYSOCKET" (you
can change this, if you want to pass a socket as an argument, just use
scalars instead of barewords for socket handles, and pass the socket like a
normal sub argument). If no activity occurs in 0.5 seconds, it will return
0. Otherwise it will return 1. You can then have a while loop somewhere in
your program that keeps checking until you get a connection, or some data,
or whatever.

sub checkfordata {
my $timeout = 0.5;  # half a second
my $bits = "";
vec($bits,fileno(MYSOCKET),1) = 1;
my $rout;
select($rout=$bits, undef, undef, $timeout);
if(vec($rout,fileno(MYSOCKET),1) == 1) {
    # We have some data to read! (connection, incoming packet, yada yada)
    return 1;
}
else {
    return 0;
}
}

Hope that helps out
Steve.


----- Original Message ----- 
From: "Nigel Cannings" <[EMAIL PROTECTED]>
To: <perl-win32-gui-users@lists.sourceforge.net>
Sent: Thursday, January 15, 2004 5:16 PM
Subject: [perl-win32-gui-users] Avoiding applications hanging?


> hi there
>
> I have a console application, that I want to have show an icon on the
status
> bar - This is no problem with Win32::GUI::Icon.
>
> However, I do not want the application to hang, waiting for an event from
> the (hidden) window - Really the icon is there to show the console app is
> running, and also to be clicked to exit.
>
> Is there any way to display the icon, but allow the main application to
> carry on doing its thing in the background (my application is listening
for
> a socket connection)
>
> Many thanks
>
> Nigel
>
>
> -------------------------------------------------------
> The SF.Net email is sponsored by EclipseCon 2004
> Premiere Conference on Open Tools Development and Integration
> See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
> http://www.eclipsecon.org/osdn
> _______________________________________________
> Perl-Win32-GUI-Users mailing list
> Perl-Win32-GUI-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
>


Reply via email to