Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
37 user(s) are online (25 user(s) are browsing Forums)

Members: 1
Guests: 36

samo79, more...

Support us!

Headlines

 
  Register To Post  

Listen on scoket and for other signals (like CTRL-C)
Just popping in
Just popping in


See User information
Hi,

does anyone know how to listen on a server socket (ISocket-listen) and on the same time listen for other signals like CTRL-C.

I'm looking for something like ISocket->WaitSelect but for a server implementation.

regards

max

Go to top
Re: Listen on scoket and for other signals (like CTRL-C)
Just popping in
Just popping in


See User information
@MigthyMax

I figured it out by myself. If somebody wants to know how to do it. You can actually use ISocket->WaitSelect for implemneting a simple server like this (simplified, no error checking etc):

ISocket->bindsocket,(struct sockaddr *)&addr,sizeof(addr) );
ISocket->listensocket,)

for( 
int loop TRUE;loop; ) {
  
fd_set listenFds;
  
FD_ZERO( &listenFds );
  
FD_SETsocket,&listenFds );

  
printf("Listening.....\n");
  
ULONG signals SIGBREAKF_CTRL_C;
  
int readyDescriptors ISocket->WaitSelectsocket +1,&listenFds,NULL,NULL,NULL,&signals );

  if( 
readyDescriptors == -) {
    
printf"Network Error.\n" );
    
loop FALSE;
  } 
  else {
    if( ( 
signals SIGBREAKF_CTRL_C ) == SIGBREAKF_CTRL_C ) {
      
printf"Detected CTRL-C.\n" );
      
loop FALSE;
    }

    if( 
FD_ISSETsocket,&listenFds ) ) {
      
int client ISocket->acceptsocket,NULL,NULL );
      if( 
client != -) {
        
printf("Client connected.\n"); 
        
ISocket->CloseSocketclient );
      }
    }
  }
}

Go to top
Re: Listen on scoket and for other signals (like CTRL-C)
Just can't stay away
Just can't stay away


See User information
thx for posting example/code

Go to top
Re: Listen on scoket and for other signals (like CTRL-C)
Just popping in
Just popping in


See User information
@MigthyMax

Shouldn't be there an 'else' in this code, like:
if( ( signals SIGBREAKF_CTRL_C ) == SIGBREAKF_CTRL_C ) {
      
printf"Detected CTRL-C.\n" );
      
loop FALSE;
    }
/* else ? */
    
if( FD_ISSETsocket,&listenFds ) ) {
      
int client ISocket->acceptsocket,NULL,NULL );
      if( 
client != -) {
        
printf("Client connected.\n"); 
        
ISocket->CloseSocketclient );
      }


For when CTRL_C has been pressed, makes it still sense to perform the 'if (FD_ISSET' part?

Just a thought.

OldFart

Go to top
Re: Listen on scoket and for other signals (like CTRL-C)
Just popping in
Just popping in


See User information
@OldFart

Personal taste. Even having got a CTRL-C, and something is present at the socket, you could
let connect the client and immediately tell him something like "service will go away".
Depends on the protocol / service you are about to to implement.

But the pasted code way copied/modified from a setup where the other signals were
from other messages ports. So not necessary from a signal indication that the program should exit.

Max

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )



Polls
Running AmigaOS 4 on?
AmigaOne SE/XE or microA1 12% (26)
Pegasos2 3% (8)
X5000 22% (48)
X1000 14% (30)
A1222 8% (19)
Sam 440/460 18% (40)
Classic PowerPC Amiga 2% (6)
WinUAE emulation 7% (16)
Qemu emulation 9% (21)
Total Votes: 214
The poll closed at 2025/12/1 12:00
6 Comments


Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project