亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? perlipc.pod

?? ARM上的如果你對(duì)底層感興趣
?? POD
?? 第 1 頁(yè) / 共 4 頁(yè)
字號(hào):

    my $waitedpid = 0;
    my $paddr;

    sub REAPER {
	$waitedpid = wait;
	$SIG{CHLD} = \&REAPER;  # loathe sysV
	logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
    }

    $SIG{CHLD} = \&REAPER;

    for ( $waitedpid = 0;
	  ($paddr = accept(Client,Server)) || $waitedpid;
	  $waitedpid = 0, close Client)
    {
	next if $waitedpid and not $paddr;
	my($port,$iaddr) = sockaddr_in($paddr);
	my $name = gethostbyaddr($iaddr,AF_INET);

	logmsg "connection from $name [",
		inet_ntoa($iaddr), "]
		at port $port";

	spawn sub {
	    print "Hello there, $name, it's now ", scalar localtime, $EOL;
	    exec '/usr/games/fortune'		# XXX: `wrong' line terminators
		or confess "can't exec fortune: $!";
	};

    }

    sub spawn {
	my $coderef = shift;

	unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE') {
	    confess "usage: spawn CODEREF";
	}

	my $pid;
	if (!defined($pid = fork)) {
	    logmsg "cannot fork: $!";
	    return;
	} elsif ($pid) {
	    logmsg "begat $pid";
	    return; # I'm the parent
	}
	# else I'm the child -- go spawn

	open(STDIN,  "<&Client")   || die "can't dup client to stdin";
	open(STDOUT, ">&Client")   || die "can't dup client to stdout";
	## open(STDERR, ">&STDOUT") || die "can't dup stdout to stderr";
	exit &$coderef();
    }

This server takes the trouble to clone off a child version via fork() for
each incoming request.  That way it can handle many requests at once,
which you might not always want.  Even if you don't fork(), the listen()
will allow that many pending connections.  Forking servers have to be
particularly careful about cleaning up their dead children (called
"zombies" in Unix parlance), because otherwise you'll quickly fill up your
process table.

We suggest that you use the B<-T> flag to use taint checking (see L<perlsec>)
even if we aren't running setuid or setgid.  This is always a good idea
for servers and other programs run on behalf of someone else (like CGI
scripts), because it lessens the chances that people from the outside will
be able to compromise your system.

Let's look at another TCP client.  This one connects to the TCP "time"
service on a number of different machines and shows how far their clocks
differ from the system on which it's being run:

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

    my $SECS_of_70_YEARS = 2208988800;
    sub ctime { scalar localtime(shift) }

    my $iaddr = gethostbyname('localhost');
    my $proto = getprotobyname('tcp');
    my $port = getservbyname('time', 'tcp');
    my $paddr = sockaddr_in(0, $iaddr);
    my($host);

    $| = 1;
    printf "%-24s %8s %s\n",  "localhost", 0, ctime(time());

    foreach $host (@ARGV) {
	printf "%-24s ", $host;
	my $hisiaddr = inet_aton($host)     || die "unknown host";
	my $hispaddr = sockaddr_in($port, $hisiaddr);
	socket(SOCKET, PF_INET, SOCK_STREAM, $proto)   || die "socket: $!";
	connect(SOCKET, $hispaddr)          || die "bind: $!";
	my $rtime = '    ';
	read(SOCKET, $rtime, 4);
	close(SOCKET);
	my $histime = unpack("N", $rtime) - $SECS_of_70_YEARS ;
	printf "%8d %s\n", $histime - time, ctime($histime);
    }

=head2 Unix-Domain TCP Clients and Servers

That's fine for Internet-domain clients and servers, but what about local
communications?  While you can use the same setup, sometimes you don't
want to.  Unix-domain sockets are local to the current host, and are often
used internally to implement pipes.  Unlike Internet domain sockets, Unix
domain sockets can show up in the file system with an ls(1) listing.

    % ls -l /dev/log
    srw-rw-rw-  1 root            0 Oct 31 07:23 /dev/log

You can test for these with Perl's B<-S> file test:

    unless ( -S '/dev/log' ) {
	die "something's wicked with the print system";
    }

Here's a sample Unix-domain client:

    #!/usr/bin/perl -w
    use Socket;
    use strict;
    my ($rendezvous, $line);

    $rendezvous = shift || '/tmp/catsock';
    socket(SOCK, PF_UNIX, SOCK_STREAM, 0)	|| die "socket: $!";
    connect(SOCK, sockaddr_un($rendezvous))	|| die "connect: $!";
    while (defined($line = <SOCK>)) {
	print $line;
    }
    exit;

And here's a corresponding server.  You don't have to worry about silly
network terminators here because Unix domain sockets are guaranteed
to be on the localhost, and thus everything works right.

    #!/usr/bin/perl -Tw
    use strict;
    use Socket;
    use Carp;

    BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
    sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }

    my $NAME = '/tmp/catsock';
    my $uaddr = sockaddr_un($NAME);
    my $proto = getprotobyname('tcp');

    socket(Server,PF_UNIX,SOCK_STREAM,0) 	|| die "socket: $!";
    unlink($NAME);
    bind  (Server, $uaddr) 			|| die "bind: $!";
    listen(Server,SOMAXCONN)			|| die "listen: $!";

    logmsg "server started on $NAME";

    my $waitedpid;

    sub REAPER {
	$waitedpid = wait;
	$SIG{CHLD} = \&REAPER;  # loathe sysV
	logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
    }

    $SIG{CHLD} = \&REAPER;


    for ( $waitedpid = 0;
	  accept(Client,Server) || $waitedpid;
	  $waitedpid = 0, close Client)
    {
	next if $waitedpid;
	logmsg "connection on $NAME";
	spawn sub {
	    print "Hello there, it's now ", scalar localtime, "\n";
	    exec '/usr/games/fortune' or die "can't exec fortune: $!";
	};
    }

As you see, it's remarkably similar to the Internet domain TCP server, so
much so, in fact, that we've omitted several duplicate functions--spawn(),
logmsg(), ctime(), and REAPER()--which are exactly the same as in the
other server.

So why would you ever want to use a Unix domain socket instead of a
simpler named pipe?  Because a named pipe doesn't give you sessions.  You
can't tell one process's data from another's.  With socket programming,
you get a separate session for each client: that's why accept() takes two
arguments.

For example, let's say that you have a long running database server daemon
that you want folks from the World Wide Web to be able to access, but only
if they go through a CGI interface.  You'd have a small, simple CGI
program that does whatever checks and logging you feel like, and then acts
as a Unix-domain client and connects to your private server.

=head1 TCP Clients with IO::Socket

For those preferring a higher-level interface to socket programming, the
IO::Socket module provides an object-oriented approach.  IO::Socket is
included as part of the standard Perl distribution as of the 5.004
release.  If you're running an earlier version of Perl, just fetch
IO::Socket from CPAN, where you'll also find find modules providing easy
interfaces to the following systems: DNS, FTP, Ident (RFC 931), NIS and
NISPlus, NNTP, Ping, POP3, SMTP, SNMP, SSLeay, Telnet, and Time--just
to name a few.

=head2 A Simple Client

Here's a client that creates a TCP connection to the "daytime"
service at port 13 of the host name "localhost" and prints out everything
that the server there cares to provide.

    #!/usr/bin/perl -w
    use IO::Socket;
    $remote = IO::Socket::INET->new(
			Proto    => "tcp",
			PeerAddr => "localhost",
			PeerPort => "daytime(13)",
		    )
		  or die "cannot connect to daytime port at localhost";
    while ( <$remote> ) { print }

When you run this program, you should get something back that
looks like this:

    Wed May 14 08:40:46 MDT 1997

Here are what those parameters to the C<new> constructor mean:

=over

=item C<Proto>

This is which protocol to use.  In this case, the socket handle returned
will be connected to a TCP socket, because we want a stream-oriented
connection, that is, one that acts pretty much like a plain old file.
Not all sockets are this of this type.  For example, the UDP protocol
can be used to make a datagram socket, used for message-passing.

=item C<PeerAddr>

This is the name or Internet address of the remote host the server is
running on.  We could have specified a longer name like C<"www.perl.com">,
or an address like C<"204.148.40.9">.  For demonstration purposes, we've
used the special hostname C<"localhost">, which should always mean the
current machine you're running on.  The corresponding Internet address
for localhost is C<"127.1">, if you'd rather use that.

=item C<PeerPort>

This is the service name or port number we'd like to connect to.
We could have gotten away with using just C<"daytime"> on systems with a
well-configured system services file,[FOOTNOTE: The system services file
is in I</etc/services> under Unix] but just in case, we've specified the
port number (13) in parentheses.  Using just the number would also have
worked, but constant numbers make careful programmers nervous.

=back

Notice how the return value from the C<new> constructor is used as
a filehandle in the C<while> loop?  That's what's called an indirect
filehandle, a scalar variable containing a filehandle.  You can use
it the same way you would a normal filehandle.  For example, you
can read one line from it this way:

    $line = <$handle>;

all remaining lines from is this way:

    @lines = <$handle>;

and send a line of data to it this way:

    print $handle "some data\n";

=head2 A Webget Client

Here's a simple client that takes a remote host to fetch a document
from, and then a list of documents to get from that host.  This is a
more interesting client than the previous one because it first sends
something to the server before fetching the server's response.

    #!/usr/bin/perl -w
    use IO::Socket;
    unless (@ARGV > 1) { die "usage: $0 host document ..." }
    $host = shift(@ARGV);
    $EOL = "\015\012";
    $BLANK = $EOL x 2;
    foreach $document ( @ARGV ) {
	$remote = IO::Socket::INET->new( Proto     => "tcp",
					 PeerAddr  => $host,
					 PeerPort  => "http(80)",
				        );
	unless ($remote) { die "cannot connect to http daemon on $host" }
	$remote->autoflush(1);
	print $remote "GET $document HTTP/1.0" . $BLANK;
	while ( <$remote> ) { print }
	close $remote;
    }

The web server handing the "http" service, which is assumed to be at
its standard port, number 80.  If your the web server you're trying to
connect to is at a different port (like 1080 or 8080), you should specify
as the named-parameter pair, C<PeerPort =E<gt> 8080>.  The C<autoflush>
method is used on the socket because otherwise the system would buffer
up the output we sent it.  (If you're on a Mac, you'll also need to
change every C<"\n"> in your code that sends data over the network to
be a C<"\015\012"> instead.)

Connecting to the server is only the first part of the process: once you
have the connection, you have to use the server's language.  Each server
on the network has its own little command language that it expects as
input.  The string that we send to the server starting with "GET" is in
HTTP syntax.  In this case, we simply request each specified document.
Yes, we really are making a new connection for each document, even though
it's the same host.  That's the way you always used to have to speak HTTP.
Recent versions of web browsers may request that the remote server leave
the connection open a little while, but the server doesn't have to honor
such a request.

Here's an example of running that program, which we'll call I<webget>:

    % webget www.perl.com /guanaco.html
    HTTP/1.1 404 File Not Found
    Date: Thu, 08 May 1997 18:02:32 GMT
    Server: Apache/1.2b6
    Connection: close
    Content-type: text/html

    <HEAD><TITLE>404 File Not Found</TITLE></HEAD>
    <BODY><H1>File Not Found</H1>
    The requested URL /guanaco.html was not found on this server.<P>
    </BODY>

Ok, so that's not very interesting, because it didn't find that
particular document.  But a long response wouldn't have fit on this page.

For a more fully-featured version of this program, you should look to
the I<lwp-request> program included with the LWP modules from CPAN.

=head2 Interactive Client with IO::Socket

Well, that's all fine if you want to send one command and get one answer,
but what about setting up something fully interactive, somewhat like
the way I<telnet> works?  That way you can type a line, get the answer,
type a line, get the answer, etc.

This client is more complicated than the two we've done so far, but if
you're on a system that supports the powerful C<fork> call, the solution
isn't that rough.  Once you've made the connection to whatever service
you'd like to chat with, call C<fork> to clone your process.  Each of
these two identical process has a very simple job to do: the parent
copies everything from the socket to standard output, while the child
simultaneously copies everything from standard input to the socket.
To accomplish the same thing using just one process would be I<much>
harder, because it's easier to code two processes to do one thing than it
is to code one process to do two things.  (This keep-it-simple principle
a cornerstones of the Unix philosophy, and good software engineering as
well, which is probably why it's spread to other systems.)

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
免费成人在线网站| 精品乱码亚洲一区二区不卡| 99久久伊人精品| 国产成人精品在线看| 久久99最新地址| 九色porny丨国产精品| 久久99国内精品| 国产美女娇喘av呻吟久久| 国产乱码精品一区二区三区av| 国产一区福利在线| 成人午夜视频在线| 一本大道av伊人久久综合| 在线观看不卡视频| 欧美男女性生活在线直播观看| 91精品国产福利在线观看| 欧美大片在线观看一区二区| 欧美精品一区二区高清在线观看| 久久婷婷国产综合精品青草| 国产精品日韩成人| 亚洲精品视频在线观看网站| 一区二区免费看| 首页综合国产亚洲丝袜| 激情综合色播激情啊| 成人自拍视频在线观看| 欧美性色黄大片| 精品美女一区二区| 国产精品入口麻豆九色| 亚洲成人av资源| 国产一区二区三区av电影| 99久久精品久久久久久清纯| 欧美日韩高清在线| 日韩亚洲欧美在线| 国产精品色婷婷久久58| 亚洲国产一区二区三区青草影视 | 首页国产欧美久久| 精品一区二区三区久久久| 成人激情图片网| 91福利国产精品| 精品久久久久久无| 亚洲欧洲精品一区二区三区| 首页综合国产亚洲丝袜| 国产成人亚洲综合色影视 | 综合色中文字幕| 亚洲bt欧美bt精品| 国产成人精品综合在线观看| 色噜噜狠狠色综合中国| 亚洲欧洲精品天堂一级 | 国产v综合v亚洲欧| 欧美日韩免费高清一区色橹橹| 久久综合久久99| 亚洲一区二区在线免费观看视频| 国产在线精品国自产拍免费| 欧美午夜在线观看| 国产欧美一区二区精品久导航 | 久久国产尿小便嘘嘘| 99免费精品在线| 精品国免费一区二区三区| 亚洲天堂久久久久久久| 久热成人在线视频| 欧美伊人久久久久久久久影院 | 久久亚洲捆绑美女| 亚洲成人综合视频| 91亚洲永久精品| 久久夜色精品国产欧美乱极品| 亚洲国产欧美一区二区三区丁香婷| 国产福利一区二区| 日韩欧美亚洲国产精品字幕久久久| 亚洲猫色日本管| 国产一区二区女| 91精品国产一区二区三区香蕉 | 成人av第一页| 26uuu欧美日本| 日韩精品一级中文字幕精品视频免费观看 | 国产suv精品一区二区三区| 91精品国产综合久久精品| 亚洲乱码日产精品bd| 国产精品1区2区| 欧美一激情一区二区三区| 夜夜精品浪潮av一区二区三区 | 国产亚洲综合性久久久影院| 日本午夜精品视频在线观看 | 在线视频欧美精品| 欧美国产日韩精品免费观看| 精品一二三四区| 91精品综合久久久久久| 亚洲一区二三区| 在线日韩一区二区| 亚洲免费观看高清完整版在线观看| 国产乱子伦视频一区二区三区| 中国色在线观看另类| 国产精品资源网| 久久综合av免费| 精品中文字幕一区二区| 日韩一二在线观看| 麻豆国产91在线播放| 91精品国产一区二区三区香蕉| 亚洲超碰97人人做人人爱| 91官网在线观看| 亚洲国产视频网站| 欧美私模裸体表演在线观看| 亚洲欧美日韩国产另类专区| 99免费精品在线观看| 亚洲色图在线播放| 色综合亚洲欧洲| 亚洲已满18点击进入久久| 欧美午夜电影在线播放| 天堂精品中文字幕在线| 欧美精品1区2区| 免费观看成人av| 精品久久五月天| 国产精品一区二区三区网站| 久久色中文字幕| 成人免费高清视频在线观看| 中文字幕一区日韩精品欧美| jlzzjlzz亚洲日本少妇| 一区二区激情视频| 欧美色涩在线第一页| 日本成人超碰在线观看| 精品国内片67194| 成人精品小蝌蚪| 亚洲乱码一区二区三区在线观看| 欧美三级电影在线观看| 秋霞电影一区二区| 久久综合999| 91麻豆精品秘密| 亚洲成a人v欧美综合天堂下载| 91精品国产综合久久精品| 国产一区欧美一区| 亚洲视频免费看| 在线电影欧美成精品| 精品一区二区三区在线观看 | 午夜精品成人在线视频| 日韩欧美久久久| 粉嫩13p一区二区三区| 悠悠色在线精品| 精品处破学生在线二十三| 丁香天五香天堂综合| 一区二区三区高清| 日韩精品一区二区三区中文精品| 国产成人av一区二区| 一区2区3区在线看| 日韩视频免费观看高清完整版| 成人一区在线看| 亚洲网友自拍偷拍| 久久精品亚洲精品国产欧美kt∨| 色国产综合视频| 韩国精品免费视频| 一区二区三区在线看| 2023国产精华国产精品| 一本色道**综合亚洲精品蜜桃冫| 另类小说欧美激情| 亚洲精品国产a| 久久久91精品国产一区二区三区| 欧美在线视频全部完| 国产成人在线观看免费网站| 亚洲图片自拍偷拍| 国产精品系列在线| 亚洲综合在线五月| 精品国产一区二区三区四区四| 91福利国产成人精品照片| 久国产精品韩国三级视频| 夜夜操天天操亚洲| 国产精品女同一区二区三区| 欧美精品v日韩精品v韩国精品v| 不卡一区二区三区四区| 免费国产亚洲视频| 亚洲一区二区精品视频| 国产精品剧情在线亚洲| 日韩欧美一区在线| 91福利在线免费观看| 国产 日韩 欧美大片| 日本中文字幕不卡| 一区二区三区四区在线| 亚洲国产精品v| 欧美www视频| 91精品国产色综合久久不卡蜜臀 | 国产在线播放一区| 丝袜诱惑制服诱惑色一区在线观看 | 中文字幕第一页久久| 精品欧美乱码久久久久久| 欧美日韩在线播放一区| 色婷婷综合久久久中文字幕| 豆国产96在线|亚洲| 国产乱码精品1区2区3区| 人禽交欧美网站| 午夜精品一区在线观看| 亚洲精品一二三| 亚洲视频资源在线| 国产丝袜美腿一区二区三区| 久久影院视频免费| 日韩欧美一二三| 欧美一区二区网站| 91精品国产综合久久蜜臀 | 亚洲色图丝袜美腿| 国产欧美一区二区精品婷婷| 久久久久久久久岛国免费| 欧美精品一区男女天堂| 日韩免费高清av| 精品久久久久99| 久久久久久日产精品|