From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,57893ac51069959a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.189.72 with SMTP id gg8mr1620215pbc.4.1327591156662; Thu, 26 Jan 2012 07:19:16 -0800 (PST) Path: lh20ni226476pbb.0!nntp.google.com!news2.google.com!postnews.google.com!hs8g2000vbb.googlegroups.com!not-for-mail From: Ada BRL Newsgroups: comp.lang.ada Subject: Re: "C - like: THIS" pointer to a task type inside a task function Date: Thu, 26 Jan 2012 07:19:16 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <19cglxkm60u91.1ezey0dra41do$.dlg@40tude.net> <2c51ce87-87ef-438c-bec5-e3b8114f0471@cf6g2000vbb.googlegroups.com> <1rp216zwnjx3j$.rjwu8m3hxgp1.dlg@40tude.net> <78412bc2-abc1-4d69-a949-487ce070a8de@o13g2000vbf.googlegroups.com> <1fir2dvz9hasf$.wk7qxfxjkp9a$.dlg@40tude.net> NNTP-Posting-Host: 164.11.203.58 Mime-Version: 1.0 X-Trace: posting.google.com 1327591156 8991 127.0.0.1 (26 Jan 2012 15:19:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 26 Jan 2012 15:19:16 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: hs8g2000vbb.googlegroups.com; posting-host=164.11.203.58; posting-account=yig7mwoAAAAAcduNbH7Dpal1sjCSAijA User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUARELSCNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7,gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Date: 2012-01-26T07:19:16-08:00 List-Id: On 25 Gen, 18:10, "Dmitry A. Kazakov" wrote: > On Wed, 25 Jan 2012 07:05:57 -0800 (PST), Ada BRL wrote: > > Just a question: > > If I have understood well, I may have just one thread connected with N > > clients through N sockets, using the SAME PORT. > > As well as from different Ethernet ports. Reading from one port using > multiple tasks is unlikely to give any performance advantage. But if you > have, for example a 4-port Ethernet controller, you might wish to assign a > separate task for each port. > > > How may I know if one client (say number 5) is connected or not? I > > need an array of connections and so on... > > Each connection has a socket. Connected/not is a state of a TCP/IP socket. > > > In the case of N readers I can know it, because there's a mapping one- > > to-one. > > > In the case unique reader with N sockets, the OS (in my case MS > > Windows 7 Pro) handles the concurrent requests of sending data to the > > reader queueing them and delivering each request per time to the > > (unique) reader. > > Select() returns list of sockets available to read without blocking. You go > through the list reading the data and pushing them further. Typically, you > have a state machine associated with each input socket. The machine is fed > by the input: often, just one octet, because you don't want to get blocked > due to a protocol error. The state machine swallows the octet and depending > on its internal state and the octet performs a transition accumulating data > as necessary. At some point it queues a request to the server. > > > I MUST BE SURE that the data is delivered to the server...what do you > > suggest me to do? Multiple readers or only one? > > Delivery is guaranteed (for TCP) and not guaranteed (UDP) independently on > the way of reading. Multiple readers is simpler to implement, so you should > try this first if the number of sockets is bearable. > > >> You could consider protected objects, as others already suggested. The > >> reader might simply queue the packet read and continue, rather than waiting > >> for a rendezvous with it. > > > Regardless to the unique reader / N readers, I have to use a protected > > object that incapsulates a buffer (implemented by an array of strings type); > > When readers perform some preprocessing, then elements of the buffer > (queue) should likely be something more advanced than mere strings. > > > the reader(s) write into this protected buffer and the server reads from it. > > Am I right? Protected objects implements mutual exclusion by > > construction. > > Yes, it is called "protected action." Waitable operations are entries, like > in the case of tasks. Instant operations are procedures. Functions access > the object in a way that guaranties coherence. > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de Thank you. Just to sum it up: The best soultion is to have: - one reader task connected by sockets on N different ports to N clients, - one protected object "buffer" that receives data from the reader and is read by the server, - one server task that processes data read from the buffer and sends data back directly to the client. The second best solution is to have N reader tasks, each with just one connection to a client (the number of clients is fixed) on a different port. I know that using just one port may result in a bottleneck. Please tell me if I am right, thanks a lot!