| |
IPC and Networking Operations
-
- accept(NEWSOCKET,GENERICSOCKET)
- Does the same thing that the accept
system call does. Returns true if it succeeded, false
otherwise. See example in section on Interprocess
Communication.
- bind(SOCKET,NAME)
- Does the same thing that the bind
system call does. Returns true if it succeeded, false
otherwise. NAME should be a packed address of the proper
type for the socket. See example in section on
Interprocess Communication.
- connect(SOCKET,NAME)
- Does the same thing that the connect
system call does. Returns true if it succeeded, false
otherwise. NAME should be a package address of the proper
type for the socket. See example in section on
Interprocess Communication.
- getpeername(SOCKET)
- Returns the packed sockaddr address of
other end of the SOCKET connection.
# An internet sockaddr
$sockaddr = 'S n a4 x8';
$hersockaddr = getpeername(S);
($family, $port, $heraddr) =
unpack($sockaddr,$hersockaddr);
- getsockname(SOCKET)
- Returns the packed sockaddr address of
this end of the SOCKET connection.
# An internet sockaddr
$sockaddr = 'S n a4 x8';
$mysockaddr = getsockname(S);
($family, $port, $myaddr) =
unpack($sockaddr,$mysockaddr);
- getsockopt(SOCKET,LEVEL,OPTNAME)
- Returns the socket option requested,
or undefined if there is an error.
- listen(SOCKET,QUEUESIZE)
- Does the same thing that the listen
system call does. Returns true if it succeeded, false
otherwise. See example in section on Interprocess
Communication.
- msgctl(ID,CMD,ARG)
- Calls the System V IPC function msgctl.
If CMD is &IPC_STAT, then ARG must be a variable
which will hold the returned msqid_ds structure. Returns
like ioctl: the undefined value for error, "0 but
true" for zero, or the actual return value otherwise.
- msgget(KEY,FLAGS)
- Calls the System V IPC function msgget.
Returns the message queue id, or the undefined value if
there is an error.
- msgsnd(ID,MSG,FLAGS)
- Calls the System V IPC function msgsnd
to send the message MSG to the message queue ID. MSG must
begin with the long integer message type, which may be
created with pack("L",
$type). Returns true if successful, or false if there is
an error.
- msgrcv(ID,VAR,SIZE,TYPE,FLAGS)
- Calls the System V IPC function msgrcv
to receive a message from message queue ID into variable
VAR with a maximum message size of SIZE. Note that if a
message is received, the message type will be the first
thing in VAR, and the maximum length of VAR is SIZE plus
the size of the message type. Returns true if successful,
or false if there is an error.
- recv(SOCKET,SCALAR,LEN,FLAGS)
- Receives a message on a socket.
Attempts to receive LENGTH bytes of data into variable
SCALAR from the specified SOCKET filehandle. Returns the
address of the sender, or the undefined value if there's
an error. SCALAR will be grown or shrunk to the length
actually read. Takes the same flags as the system call of
the same name.
- semctl(ID,SEMNUM,CMD,ARG)
- Calls the System V IPC function semctl.
If CMD is &IPC_STAT or &GETALL, then ARG must be
a variable which will hold the returned semid_ds
structure or semaphore value array. Returns like ioctl:
the undefined value for error, "0 but true" for
zero, or the actual return value otherwise.
- semget(KEY,NSEMS,SIZE,FLAGS)
- Calls the System V IPC function semget.
Returns the semaphore id, or the undefined value if there
is an error.
- semop(KEY,OPSTRING)
- Calls the System V IPC function semop
to perform semaphore operations such as signaling and
waiting. OPSTRING must be a packed array of semop
structures. Each semop structure can be generated with
'pack("sss", $semnum, $semop, $semflag)'. The
number of semaphore operations is implied by the length
of OPSTRING. Returns true if successful, or false if
there is an error. As an example, the following code
waits on semaphore $semnum of semaphore id $semid:
$semop = pack("sss", $semnum, -1, 0);
die "Semaphore trouble: $!\n" unless semop($semid, $semop);
To signal the semaphore, replace
"-1" with "1".
- send(SOCKET,MSG,FLAGS,TO)
- send(SOCKET,MSG,FLAGS)
- Sends a message on a socket. Takes the
same flags as the system call of the same name. On
unconnected sockets you must specify a destination to
send TO. Returns the number of characters sent, or the
undefined value if there is an error.
- setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
- Sets the socket option requested.
Returns undefined if there is an error. OPTVAL may be
specified as undef if you don't want to pass an argument.
- shmctl(ID,CMD,ARG)
- Calls the System V IPC function shmctl.
If CMD is &IPC_STAT, then ARG must be a variable
which will hold the returned shmid_ds structure. Returns
like ioctl: the undefined value for error, "0 but
true" for zero, or the actual return value otherwise.
- shmget(KEY,SIZE,FLAGS)
- Calls the System V IPC function shmget.
Returns the shared memory segment id, or the undefined
value if there is an error.
- shmread(ID,VAR,POS,SIZE)
- shmwrite(ID,STRING,POS,SIZE)
- Reads or writes the System V shared
memory segment ID starting at position POS for size SIZE
by attaching to it, copying in/out, and detaching from it.
When reading, VAR must be a variable which will hold the
data read. When writing, if STRING is too long, only SIZE
bytes are used; if STRING is too short, nulls are written
to fill out SIZE bytes. Return true if successful, or
false if there is an error.
- shutdown(SOCKET,HOW)
- Shuts down a socket connection in the
manner indicated by HOW, which has the same
interpretation as in the system call of the same name.
- socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
- Opens a socket of the specified kind
and attaches it to filehandle SOCKET. DOMAIN, TYPE and
PROTOCOL are specified the same as for the system call of
the same name. You may need to run h2ph on sys/socket.h
to get the proper values handy in a perl library file.
Return true if successful. See the example in the section
on Interprocess Communication.
- socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
- Creates an unnamed pair of sockets in
the specified domain, of the specified type. DOMAIN, TYPE
and PROTOCOL are specified the same as for the system
call of the same name. If unimplemented, yields a fatal
error. Return true if successful.
|
|
|