🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #76

Re: Nesecito crear un servidor concurrente, alguien que me ayude por favor

#76
From: Pascal Bourguignon
Date: Tue, 21 Oct 2003 05:02
40 lines
2674 bytes
luismnieto@fibertel.com.ar (Luis Nieto) writes:

> Nesecito crear un servidor concurrente y estoy usando la fundion
> fork(), estuve viendo la forma de usarla en algunos codigos de
> ejemplo. Pero no logro hacerla andar correctamente, para mi juicio.
> Con esta funcion deberia poder aceptar varias conexiones y manejarlas
> simultaneamente a todas??
> de ser asi alguien me podria explicar como usarla, porque yo logro la
> conexion de varios cliente, pero hasta que no termina de atender a uno
> no empieza con otro.
> Gracias

Para  acceptar  conexiones,  hay  que  crear  un  socket  y  llamar  a
listen(2). Cuando una nueva conexi�n llega, llamar a accept(2) y hacer
el  fork(2).  El  proceso padre  puede  cerrar el  socket abierto  con
accept(), y volver al listen, mientras el hiro procesa la conexi�n.


    daemonize()
        bind() the sockets, change_uid(),
        fork() a master process where it setsid() and calls listening_process(),
        write the pid of master process into the pidfile and exits.

    listening_process()
        listen() the sockets,
        then for ever 
             poll() the sockets,
             accept() the incoming connections and
             calls handle_connection().

    handle_connection()
        fork() a worker process  working wit the accepted socket,
        while the parent just closes it.
    

-- 
__Pascal_Bourguignon__
http://www.informatimago.com/
Do not adjust your mind, there is a fault in reality.
Lying for having sex or lying for making war?  Trust US presidents :-(
Technical Details
Message-ID: <874qy3dvze.fsf@thalassa.informatimago.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!skynet.be!skynet.be!fu-berlin.de!uni-berlin.de!thalassa.informatimago.COM!not-for-mail
References: <73879088.0310201206.1433aa0e@posting.google.com>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f9fe1,48c69b5d3af6a55e
X-Google-Attributes: gidf9fe1,public
X-Google-Thread: f86c8,48c69b5d3af6a55e
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-10-20 22:02:16 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!skynet.be!skynet.be!fu-berlin.de!uni-berlin.de!thalassa.informatimago.COM!not-for-mail
From: Pascal Bourguignon <spam@thalassa.informatimago.com>
Newsgroups: es.comp.os.linux.programacion,es.comp.os.linux
Subject: Re: Nesecito crear un servidor concurrente, alguien que me ayude por favor
Date: 21 Oct 2003 07:02:13 +0200
Organization: informatimago.com
Lines: 40
Message-ID: <874qy3dvze.fsf@thalassa.informatimago.com>
References: <73879088.0310201206.1433aa0e@posting.google.com>
NNTP-Posting-Host: thalassa.informatimago.com (195.114.85.198)
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 1066712535 29691233 195.114.85.198 (16 [41911])
User-Agent: Gnus/5.09 (Gnus v5.9.0) 21.3.50.pjb1.1