-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-seqpkt.pl
executable file
·49 lines (39 loc) · 1.13 KB
/
test-seqpkt.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
# -*- mode: cperl; cperl-indent-level: 4 -*-
# $ test-seqpkt.pl $
#
# Author: Tomi Ollila -- too ät iki piste fi
#
# Copyright (c) 2018 Tomi Ollila
# All rights reserved
#
# Created: Thu 22 Nov 2018 20:04:18 EET too
# Last modified: Sat 19 Jan 2019 19:24:20 +0200 too
# SPDX-License-Identifier: BSD-2-Clause
# observe that seqpacket sockets preserve message boundaries
# and, by using small bufsize, data drop on seqpacket sockets
use 5.8.1;
use strict;
use warnings;
use Socket;
$ENV{'PATH'} = '/sbin:/usr/sbin:/bin:/usr/bin';
die "
Usage: $0 '(s|p)' [bufsize]\n
s: SOCK_STREAM -- p: SOCK_SEQPACKET socket\n
bufsize: read buffer size if given\n\n" unless @ARGV;
my $type;
if ($ARGV[0] eq 's') { $type = SOCK_STREAM }
elsif ($ARGV[0] eq 'p') { $type = SOCK_SEQPACKET }
else { die "'$ARGV[0]' not 's' nor 'p'\n" }
my $bufsize = ($ARGV[1] || 0) + 0;
$bufsize = 512 unless $bufsize > 0;
socketpair S1, S2, AF_UNIX, $type, 0;
syswrite S1, "<message 1>";
syswrite S1, "<message 2>";
syswrite S1, "<message 3>";
syswrite S1, "EOF";
while (1) {
sysread S2, $_, $bufsize or die $!;
print $_, "\n";
last if /EOF/;
}