socket async io

unix

    Next

  • 1. sem_wait() not returning
    Hi I'm just trying out some test code using posix semaphores on linux 2.6 but can't seem to get them to work properly. I've probably done something wrong but can anyone see what? In the code below the sem_wait () call in the child process blocks indefinately for some reason though sem_post() returns without any errors. Thanks for any help. #include <stdio.h> #include <error.h> #include <errno.h> #include <semaphore.h> int main() { sem_t sem; if (sem_init(&sem,1,0) == -1) { perror("sem_init()"); return 1; } switch(fork()) { case -1: perror("fork()"); return 1; case 0: printf("Child %u waiting for child to set semaphore... \n",getpid()); if (sem_wait(&sem) == -1) { perror("sem_wait()"); return 1; } puts("Done"); return 0; } sleep(1); printf("Parent %u setting semaphore...\n",getpid()); if (sem_post(&sem) == -1) { perror("sem_post()"); return 1; } puts("Set"); return 0; } B2003
  • 2. Building a pipe "by hand" in C?
    Hello, I need to get some data through a sequence of external commands. Currently I write out my data to some a temporary file "/tmp/out.dat", then invoke system("foo < /tmp/out.dat | bar | baz > /tmp/in.dat"), then I read "/tmp/in.dat" back into my program. What I don't like about this is that this solution relies on the existence of a shell -- but it also relies on other external programs, making this point more of an aesthetic one. What bothers me more is that I'm implementing this on a system with very sluggish file I/O (pretty much everything goes through a network), so I'd like to do away with the temp files. Third, in case of a failure I don't have access to the individual external commands' stderrs or exit codes. How is this done in C? Python, interestingly, offers the functions popen2()..popen4() that could be used in this way. Thanks, robert
  • 3. API to get the number of network interfaces
    Hi Everyone, I'm looking for a system call or a library routine to fetch the number of network interfaces of the machine (including the virtual interfaces like 127.0.0.1 and any other, if created). I know the windows equivalent, which is GetNumberOfInterfaces. But so far, not been able to find out the UNIX equivalent. Please help me. Thanks in advance ! ! !

socket async io

Postby Xend » Sat, 22 Nov 2008 18:25:27 GMT

can i use fcntl(socket_fd, F_SETSIG, signum) to get asycn event on
socket_fd with socket.

Re: socket async io

Postby Maxim Yegorushkin » Sat, 22 Nov 2008 19:20:41 GMT



You can, but it is pretty much useless because it is very inconvenient
to deal with signals for doing IO. It is much more convenient to use
non-blocking IO (select, pool, epoll, ...) or aio_ family of functions
(aio_read and friends).

 http://www.**--****.com/ 
 http://www.**--****.com/ 

Max

Re: socket async io

Postby Rainer Weikusat » Sat, 22 Nov 2008 22:06:29 GMT

Xend < XXXX@XXXXX.COM > writes:

On Linux, yes. But (AFAIK) asynchronous I/O with the help of signals
is only availabe either on Linux or *BSD.

Re: socket async io

Postby Rainer Weikusat » Sat, 22 Nov 2008 22:15:12 GMT

Maxim Yegorushkin < XXXX@XXXXX.COM > writes:



I have several programs which use signal-driven I/O for various
reasons, the most important being the absence of a extended
multiplexing mechansim other than using queued RT signals on Linux
2.4. Using edge triggered I/O readiness notifaction requires
marginally more complicated code than using a level-triggered
interface. But dealing with signal-driven I/O or signals in general
isn't least bit of what I would consider 'inconvenient to the point of
uselessness'[*].

[*] That 9.5 out of 7 hardware designers cannot think of any other
event notification mechanism than high-freqeuncy polling of a
(conceptually) passive data source has so far not led to the
un-invention of interrupts :->>.

Re: socket async io

Postby Maxim Yegorushkin » Sat, 22 Nov 2008 23:54:42 GMT




What does it prove?


I was not referring to edge-triggered I/O.


Given choice of demultiplexing using select, poll, epoll, etc.. and
signal driven I/O, I consider demultiplexing more convenient. But this
is just my opinion.


Huh?

Max

Re: socket async io

Postby Rainer Weikusat » Sun, 23 Nov 2008 00:24:23 GMT

Maxim Yegorushkin < XXXX@XXXXX.COM > writes:




That both of us have access to USENET although none of us must
necessarily be a human and not a script?


No, I was. Using signal-driven I/O implies using edge-triggered
I/O-readiness notfication and this is, in turn, (marginally) more
complicated than using level-triggered I/O-readiness notification. But
that's caused by the edge-triggerdness of the mechanism and not by
its use of signals to deliver the notifications.


So far, this is your firm belief. In my opinion, your belief is
misguided because I couldn't find anything particularly inconvenient
when using signal-driven I/O except the abovementioned
edge-triggeredness.


 http://www.**--****.com/ 

"All you can eat".

Similar Threads:

1.Need help with a simple UNIX sockets server based on IO::Socket::UNIX

Hi. I've tried to create a simple client + server that communicate
through a unix socket.

As with all socket servers, it has a loop where it waits for
connections:

while ($client = $sock->accept()) {
  # handle client here
}

The problem is that $sock->accept() is returning undef on each
alternate client connection with error "No child processes".

I made this temporary workaround that does work but of course I must be
screwing up somewhere else:

while ($client = $sock->accept() || $client = $sock->accept()) {
  # handle client here
}

I hope someone can help or provide an example. I've included the client
+ server code below for those who are interrested in taking a peek.

Thanks,
Craig Manley

############ client ############
#!/usr/bin/perl -w
use strict;
use IO::Socket;

my $sockname = 'mysocket';

my $client = IO::Socket::UNIX->new('Peer' => $sockname,
                                   'Type' => SOCK_STREAM,
                                   'Timeout' => 50) or die "$0: error
connecting to '$sockname': $ [at] \n";
my $pid = fork();
unless(defined($pid)) {
  die("Fork this! I cannot forking fork!\n");
}
if ($pid) {
  write_sock();
  waitpid($pid, 0);
}
else {
  read_sock();
}

sub write_sock {
  for (1..10) {
    print $client "testline number $_\n"; # print to socket
  }
  print $client "\n"; # empty line causes server to terminate
connection
  print "Done writing.\n"; # (goes to stdout, not socket)
}

sub read_sock {
  while (my $line = <$client>) {
    print $line; # report to stdout
    # simulate someone reading slooowly (50ms/line):
    select(undef, undef, undef, 0.05);
  }
}




########### server ############
#!/usr/bin/perl -w
use strict;
use IO::Socket;
use POSIX ":sys_wait_h"; # (for WNOHANG)
use Data::Dumper qw(Dumper);

# example using unix domain socks
# once the file is created as a socket, any client can
# interact with it

my $sockname = 'mysocket';


service_clients( get_sock() ); # wait for incoming requests


sub get_sock {
  unlink $sockname;
  my $sock = IO::Socket::UNIX->new('Local'  => $sockname,
                                   'Type'   => SOCK_STREAM,
                                   'Listen' => SOMAXCONN) || die "$0:
error starting daemon on '$sockname': $ [at] \n";
  # you might want to change permissions and ownership, e.g.:
  #chmod 0600, $sockname;
  #chown scalar getpwnam('nobody'), 0, $sockname;
  return $sock;
}

sub service_clients {
  my $sock = shift;
  $SIG{CHLD} = \&reaper;
  my $client;
  while ($client = $sock->accept()) { # Why the hell does it return
undef on the next iteration?
  # while ($client = $sock->accept() || $client = $sock->accept()) { #
This strangely enough does work.

    # fork yet another process to prevent buffer deadlock. one proc
writes to
    # the sock, the other reads the deamons response
    my $pid = fork();
    unless(defined($pid)) {
      die("Fork this! I cannot forking fork!\n");
    }
    if ($pid) { # parent
      print "$pid $$: I'm the parent and am going to wait for another
client.\n";
      close($client); # no use to parent
      next; # be ready for another client
    }
    print "$pid $$: I'm the child and I'm going to service the
client.\n";
    # child
    close($sock); # no use to child
    process_requests($client);
    print "$pid $$: I'm the child and I'm going to exit.\n";
    exit; # terminate child
  }
  print "Damnit! I'm the server and I finished unexpectedly: $!\n";
}

sub process_requests {
  my $client = shift;
  $0 = "unixsockd: handling requests...";
  # read from client until empty line which causes it to close
connection
  while ( my $line = <$client> ) { # read line from socket
    if ($line =~ /^\s$/) {
      last; # exit on empty line
    }
    chomp($line);
    # put some more useful code here to read each line or whatever...
    printf $client "%s: %s, handled by PID %d\n",
    scalar localtime(time), $line, $$;
    # return something to client
  }
}

sub reaper {
  while (waitpid(-1,WNOHANG) > 0) {}
  $SIG{CHLD} = \&reaper;
}

2.directio and async io on redhat linux 3 and oracle 9i

Hi Folks

I have enabled directio and async io on my redhat box.

Async io is verified by running the classical cat
/etc/proc/slabinfo|grep kio

How do i verify direct io is being used by oracle.

I know of one way to do it is tracing the dbwr and seeing whether fopen
call is with o_direct flags.But the strange thing is when i say

sqlplus>conn /as sysdba;

sqlplus>oradebug setospid <<ospid-of-dbwriter>>

no trace file is being produced.Can somebody tell me what magic needs
to be done by me :-)

regards
Hrishy

3.Redhat linux and async io

Hi,

Oracle10g 10.2.0.1 (32 bit)
RHEL 4 update 3 (32 bit)

* I have installed the async io rpm's
$ rpm -qa | grep aio
libaio-0.3.102-1
libaio-devel-0.3.102-1

Questions:
1) How do i verify/check if the async io is enabled/loaded in RHEL
kernel?
I solaris I used to
$ modinfo | grep kaio
142  1344ccb   4916 178   1  kaio (kernel Async I/O)
142  1344ccb   4916 178   1  kaio (kernel Async I/O for 32 bit com)

One of the Metalink docs says check
$ cat /proc/slabinfo | grep kio

2) How do I determine if the redlat linux installed is 32 or 64 bit
version?
Is getconf LONG_BIT the only way to determine this or will uname -a
show something specific.

Thanks for your help.
wagen

4.async io

How do I enable async io on solaris 8 2/02 ?  How do I tell if it is enabled
if using veritas foundation suite?


5.How to provide Async IO support in a driver

Hi,

I am having trouble getting the aio_read and aio_suspend calls to work
properly with a driver we have written to do DMA transfers via the PCI bus.
I do not know if the driver is properly configured to enable the async
xxxaread cb_ops function.  I have searched high and low and cannot find
anything written on this topic.  Does anyone know under what conditions the
xxxaread cb_ops function is called?  In tracing my drivers activity, even
though I call aio_read from the user process, the xxxread cb_ops is always
called by the kernel.  Although I am able to start the DMA, I am having
trouble getting biodone to properly notify the user process, particularly
when it is called from a timeout routine.

I am running Solaris 8/9.  Any information on how to properly write drivers
that support async io or how to properly time out DMA completion would be
greatly appreciated.

Regards,

Mike



6. [PATCH] [1/3] writes: report truncate and io errors on async writes

7. [PATCH 5/5] direct-io: fix double completion on partially valid async requests

8. [PATCH 4/5] direct-io: unify sync and async completion paths



Return to unix

 

Who is online

Users browsing this forum: No registered users and 71 guest