Re: problem in select

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi
  1) one way is to have a master thread and make a
queue and let the two threads eat data from queue

  2) is to use multiplexing at the socket interface
level by IP aliasing. alias the original ip with
differnt ip address and bind to same port 
on the 2 threads. then any data on that port on
original ip will come to u but client will have to use
different ips (aliases ) to connect and send to u.

regards
  divyank




--- vikram b <vikramb11@xxxxxxxxx> wrote:

> Thanks for all the repls. I fully agree that select
> work this way.
> Now  i want to experiment with divyank's suggestion
> ...do u mean IP  aliasing ?
> assigning two IPs .? .seems not suitable for my app.
> ...
> can there be any other way to read data from a port
> from two threads
> 
> regards
> 
> Vikram
> 
> On 5/18/06, divyank shukla <divyank_s@xxxxxxxxx>
> wrote:
> > Yeah I think is perfectly normal
> > Select will unblock in only one of the threads..
> >
> > (Usually this done )1) What u can do is have a
> master
> > thread bind and listen
> > to the socket + port and then depending on ur need
> > u can spawn threads to perfom operations on the
> data.
> >
> > If however u need interface level multiplexing of
> > socket what u can do is use SO_REUSEADDR option
> and
> > create alias to ur socket address (using
> ifconfig)and
> > then bind on different sockt address alias but on
> same
> > port. That way two threads will listen to
> (actually
> > )socket address but different alias.
> >
> >
> > regards
> >   divyank
> >
> >
> >
> >
> > --- Manjunath Naik <peter.desouzain@xxxxxxxxx>
> wrote:
> >
> > > On 5/19/06, tyler@xxxxxxxx <tyler@xxxxxxxx>
> wrote:
> > > >
> > > > On Wed, May 17, 2006 at 09:59:38PM -0700,
> vikram b
> > > wrote:
> > > > > Hi All,
> > > > >           I dont know whether this is right
> > > place to put this ( Pls
> > > > suggest if
> > > > > anybody know correct place)
> > > > > I am trying to use select system call to
> read
> > > from network socket. I
> > > > have
> > > > > opened a socket and bind it on a port
> > > > > I have two threads (user space) each having
> a
> > > select , who is waiting on
> > > > same
> > > > > Socket FD.
> > > > > When i send any data , only one of the
> thread is
> > > getting the data ...
> > > > > Is it normal ? Can i have any ways to have
> data
> > > to both select ?
> > > > >
> > > > > Any suggestion will be of great help
> > > > >
> > > > >
> > > > > thanks in advance
> > > > >
> > > > > vikram
> > > > >
> > > > Hi,
> > > >
> > > > yes, it's normal. It's not the goal of select.
> > > >
> > > > In fact, in your case, what you do is just
> reading
> > > from the socket in a
> > > > thread. The data is taken from the socket.
> Then
> > > the other do another
> > > > read and there's no data.
> > > >
> > > > If you want the data to be received by the two
> > > processes, you should
> > > > share it (threads have the same adress space,
> it's
> > > easy to do without
> > > > any mechanism).
> > > >
> > > > In your case, if 2 threads want the data
> received
> > > (let's say thread A
> > > > and thread B), you should do 3 threads :
> > > > the first thread which just reads from the
> socket.
> > > When data is
> > > > received, it wakes up threads A and B.
> > > >
> > > >
> > > > --
> > > > tyler
> > > > tyler@xxxxxxxx
> > > >
> > > >
> > > I agree with tyler. I am not able to understand
> why
> > > in two threads you want
> > > to wait on same socket descriptor?
> > >
> > > Once the data has been read from the socket it
> has
> > > been removed from the
> > > buffer.
> > >
> > > since you are working with threads and both run
> on
> > > the same address process,
> > > i think you can shared the data between them
> once
> > > one of the threads reads
> > > it though notification mechanism.
> > >
> > > I think theoritically it may possible with only
> two
> > > thread also. Whenever
> > > one thread receives the data let it notify other
> > > thread. I am not sure
> > > whether it is possible practically. If I am
> wrong
> > > Please correct me tyler.
> > >
> > > Thanks
> > > Manjunath Naik
> > >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> > --
> > Kernelnewbies: Help each other learn about the
> Linux kernel.
> > Archive:      
> http://mail.nl.linux.org/kernelnewbies/
> > FAQ:           http://kernelnewbies.org/faq/
> >
> >
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux