International English version Traditional Chinese version
Domain Registration with Web HostingWeb site Hosting with Various supportRegistrar Transfer with Web Hosting

IPC and networking operations in PERL script



accept(newsocket,genericsocket)
Does the same thing that the accept system call does. Returns true if it succeeded, false otherwise.

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.

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.

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.

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.

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.

Back to the Perl Expressions index

Home | Support | Check | Host | Transfer | Whois | More Technology Services

© 1996-2008 Wyith Ltd dba DomainAvenue.com. All rights reserved.

Canada | USA | UK | Belgium | Italy | Hongkong | Singapore