accept(3) accept(3) bind(3) bind(3) accept − accept a connection on a socket

accept(3) accept(3) bind(3) bind(3) accept − accept a connection on a socket
accept(3)
accept(3)
NAME
bind(3)
bind(3)
NAME
accept − accept a connection on a socket
bind − bind a name to a socket
SYNOPSIS
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/socket.h>
int accept(int s, struct sockaddr *addr, int *addrlen);
int bind(int s, const struct sockaddr *name, int namelen);
DESCRIPTION
DESCRIPTION
The argument s is a socket that has been created with socket(3N) and bound to an address with bind(3N),
and that is listening for connections after a call to listen(3N). The accept( ) function extracts the first connection on the queue of pending connections, creates a new socket with the properties of s, and allocates a
new file descriptor, ns, for the socket. If no pending connections are present on the queue and the socket is
not marked as non-blocking, accept( ) blocks the caller until a connection is present. If the socket is
marked as non-blocking and no pending connections are present on the queue, accept( ) returns an error as
described below. The accept( ) function uses the netconfig(4) file to determine the STREAMS device file
name associated with s. This is the device on which the connect indication will be accepted. The accepted
socket, ns, is used to read and write data to and from the socket that connected to ns; it is not used to accept
more connections. The original socket (s) remains open for accepting further connections.
bind( ) assigns a name to an unnamed socket. When a socket is created with socket(3N), it exists in a name
space (address family) but has no name assigned. bind( ) requests that the name pointed to by name be
assigned to the socket.
RETURN VALUES
If the bind is successful, 0 is returned. A return value of −1 indicates an error, which is further specified in
the global errno.
ERRORS
The bind( ) call will fail if:
EACCES
The argument addr is a result parameter that is filled in with the address of the connecting entity as it is
known to the communications layer. The exact format of the addr parameter is determined by the domain
in which the communication occurs.
The argument addrlen is a value-result parameter. Initially, it contains the amount of space pointed to by
addr; on return it contains the length in bytes of the address returned.
The accept( ) function is used with connection-based socket types, currently with SOCK_STREAM.
It is possible to select(3C) or poll(2) a socket for the purpose of an accept( ) by selecting or polling it for a
read. However, this will only indicate when a connect indication is pending; it is still necessary to call
accept( ).
RETURN VALUES
The requested address is protected and the current user has inadequate permission
to access it.
EADDRINUSE
The specified address is already in use.
EADDRNOTAVAIL
The specified address is not available on the local machine.
EBADF
s is not a valid descriptor.
EINVAL
namelen is not the size of a valid address for the specified address family.
EINVAL
The socket is already bound to an address.
ENOSR
There were insufficient STREAMS resources for the operation to complete.
ENOTSOCK
s is a descriptor for a file, not a socket.
The following errors are specific to binding names in the UNIX domain:
The accept( ) function returns −1 on error. If it succeeds, it returns a non-negative integer that is a descriptor for the accepted socket.
EACCES
ERRORS
Search permission is denied for a component of the path prefix of the pathname in
name.
accept( ) will fail if:
EIO
An I/O error occurred while making the directory entry or allocating the inode.
EBADF
The descriptor is invalid.
EISDIR
A null pathname was specified.
EINTR
The accept attempt was interrupted by the delivery of a signal.
ELOOP
Too many symbolic links were encountered in translating the pathname in name.
The per-process descriptor table is full.
ENOENT
A component of the path prefix of the pathname in name does not exist.
ENODEV
The protocol family and type corresponding to s could not be found in the netconfig file.
ENOTDIR
A component of the path prefix of the pathname in name is not a directory.
EROFS
The inode would reside on a read-only file system.
ENOMEM
There was insufficient user memory available to complete the operation.
SEE ALSO
EPROTO
A protocol error has occurred; for example, the STREAMS protocol stack has not
been initialized or the connection has already been released.
NOTES
EMFILE
EWOULDBLOCK
The socket is marked as non-blocking and no connections are present to be
accepted.
unlink(2), socket(3N), attributes(5), socket(5)
Binding a name in the UNIX domain creates a socket in the file system that must be deleted by the caller
when it is no longer needed (using unlink(2)).
The rules used in name binding vary between communication domains.
SEE ALSO
poll(2), bind(3N), connect(3N), listen(3N), select(3C), socket(3N), netconfig(4), attributes(5), socket(5)
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
opendir/readdir(3)
opendir/readdir(3)
NAME
fopen/fdopen(3)
fopen/fdopen(3)
NAME
opendir − open a directory / readdir − read a directory
fopen, fdopen − stream open functions
SYNOPSIS
SYNOPSIS
#include <sys/types.h>
#include <stdio.h>
#include <dirent.h>
FILE *fopen(const char * path, const char *mode);
FILE *fdopen(int fildes, const char *mode);
DIR *opendir(const char *name);
DESCRIPTION
The fopen function opens the file whose name is the string pointed to by path and associates a stream with
it.
struct dirent *readdir(DIR *dir);
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
The argument mode points to a string beginning with one of the following sequences (Additional characters
may follow these sequences.):
DESCRIPTION opendir
The opendir() function opens a directory stream corresponding to the directory name, and returns a pointer
to the directory stream. The stream is positioned at the first entry in the directory.
RETURN VALUE
r
Open text file for reading. The stream is positioned at the beginning of the file.
r+
Open for reading and writing. The stream is positioned at the beginning of the file.
w
Truncate file to zero length or create text file for writing. The stream is positioned at the beginning
of the file.
w+
Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The
stream is positioned at the beginning of the file.
a
Open for appending (writing at end of file). The file is created if it does not exist. The stream is
positioned at the end of the file.
a+
Open for reading and appending (writing at end of file). The file is created if it does not exist.
The stream is positioned at the end of the file.
The opendir() function returns a pointer to the directory stream or NULL if an error occurred.
DESCRIPTION readdir
The readdir() function returns a pointer to a dirent structure representing the next directory entry in the
directory stream pointed to by dir. It returns NULL on reaching the end-of-file or if an error occurred.
DESCRIPTION readdir_r
The readdir_r() function initializes the structure referenced by entry and stores a pointer to this structure
in result. On successful return, the pointer returned at *result will have the same value as the argument
entry. Upon reaching the end of the directory stream, this pointer will have the value NULL.
The data returned by readdir() is overwritten by subsequent calls to readdir() for the same directory
stream.
The dirent structure is defined as follows:
struct dirent {
long
d_ino;
/* inode number */
off_t
d_off;
/* offset to the next dirent */
unsigned short d_reclen;
/* length of this record */
unsigned char d_type;
/* type of file */
char
d_name[256]; /* filename */
};
The fdopen function associates a stream with the existing file descriptor, fildes. The mode of the stream
(one of the values "r", "r+", "w", "w+", "a", "a+") must be compatible with the mode of the file descriptor.
The file position indicator of the new stream is set to that belonging to fildes, and the error and end-of-file
indicators are cleared. Modes "w" or "w+" do not cause truncation of the file. The file descriptor is not
dup’ed, and will be closed when the stream created by fdopen is closed. The result of applying fdopen to a
shared memory object is undefined.
RETURN VALUE
Upon successful completion fopen, fdopen and freopen return a FILE pointer. Otherwise, NULL is
returned and the global variable errno is set to indicate the error.
ERRORS
EINVAL
The mode provided to fopen, fdopen, or freopen was invalid.
RETURN VALUE
The readdir() function returns a pointer to a dirent structure, or NULL if an error occurs or end-of-file is
reached.
readdir_r() returns 0 if successful or an error number to indicate failure.
The fopen, fdopen and freopen functions may also fail and set errno for any of the errors specified for the
routine malloc(3).
The fopen function may also fail and set errno for any of the errors specified for the routine open(2).
The fdopen function may also fail and set errno for any of the errors specified for the routine fcntl(2).
ERRORS
SEE ALSO
EACCES
Permission denied.
open(2), fclose(3), fileno(3)
ENOENT
Directory does not exist, or name is an empty string.
ENOTDIR
name is not a directory.
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
getc/fgets(3)
getc/fgets(3)
NAME
ip(7)
ip(7)
NAME
fgetc, fgets, getc, getchar, gets, ungetc − input of characters and strings
ip − Linux IPv4 protocol implementation
SYNOPSIS
SYNOPSIS
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
int fgetc(FILE *stream);
char *fgets(char *s, int size, FILE *stream);
int getc(FILE *stream);
int getchar(void);
char *gets(char *s);
int ungetc(int c, FILE *stream);
tcp_socket = socket(PF_INET, SOCK_STREAM, 0);
raw_socket = socket(PF_INET, SOCK_RAW, protocol);
udp_socket = socket(PF_INET, SOCK_DGRAM, protocol);
DESCRIPTION
The programmer’s interface is BSD sockets compatible. For more information on sockets, see socket(7).
DESCRIPTION
fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on
end of file or error.
getc() is equivalent to fgetc() except that it may be implemented as a macro which evaluates stream more
than once.
getchar() is equivalent to getc(stdin).
gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF,
which it replaces with ’\0’. No check for buffer overrun is performed (see BUGS below).
fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to
by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A ’\0’ is
stored after the last character in the buffer.
ungetc() pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations. Pushed-back characters will be returned in reverse order; only one pushback is guaranteed.
An IP socket is created by calling the socket(2) function as socket(PF_INET, socket_type, protocol).
Valid socket types are SOCK_STREAM to open a tcp(7) socket, SOCK_DGRAM to open a udp(7)
socket, or SOCK_RAW to open a raw(7) socket to access the IP protocol directly. protocol is the IP protocol in the IP header to be received or sent. The only valid values for protocol are 0 and IPPROTO_TCP
for TCP sockets and 0 and IPPROTO_UDP for UDP sockets.
When a process wants to receive new incoming packets or connections, it should bind a socket to a local
interface address using bind(2). Only one IP socket may be bound to any given local (address, port) pair.
When INADDR_ANY is specified in the bind call the socket will be bound to all local interfaces. When
listen(2) or connect(2) are called on a unbound socket the socket is automatically bound to a random free
port with the local address set to INADDR_ANY.
ADDRESS FORMAT
An IP socket address is defined as a combination of an IP interface address and a port number. The basic IP
protocol does not supply port numbers, they are implemented by higher level protocols like tcp(7).
Calls to the functions described here can be mixed with each other and with calls to other input functions
from the stdio library for the same input stream.
struct sockaddr_in {
sa_family_t
sin_family;
u_int16_t
sin_port;
struct in_addr sin_addr;
};
/* Internet address. */
struct in_addr {
u_int32_t
s_addr;
};
For non-locking counterparts, see unlocked_stdio(3).
RETURN VALUE
fgetc(), getc() and getchar() return the character read as an unsigned char cast to an int or EOF on end of
file or error.
gets() and fgets() return s on success, and NULL on error or when end of file occurs while no characters
have been read.
ungetc() returns c on success, or EOF on error.
/* address family: AF_INET */
/* port in network byte order */
/* internet address */
/* address in network byte order */
sin_family is always set to AF_INET. This is required; in Linux 2.2 most networking functions return
EINVAL when this setting is missing. sin_port contains the port in network byte order. The port numbers
below 1024 are called reserved ports. Only processes with effective user id 0 or the
CAP_NET_BIND_SERVICE capability may bind(2) to these sockets.
CONFORMING TO
C89, C99. LSB deprecates gets().
BUGS
Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters
gets() will read, and because gets() will continue to store characters past the end of the buffer, it is
extremely dangerous to use. It has been used to break computer security. Use fgets() instead.
sin_addr is the IP host address. The addr member of struct in_addr contains the host interface address in
network order. in_addr should be only accessed using the inet_aton(3), inet_addr(3), inet_makeaddr(3)
library functions or directly with the name resolver (see gethostbyname(3)).
It is not advisable to mix calls to input functions from the stdio library with low-level calls to read(2) for
the file descriptor associated with the input stream; the results will be undefined and very probably not what
you want.
Note that the address and the port are always stored in network order. In particular, this means that you
need to call htons(3) on the number that is assigned to a port. All address/port manipulation functions in
the standard library work in network order.
SEE ALSO
read(2), write(2), ferror(3), fgetwc(3), fgetws(3), fopen(3), fread(3), fseek(3), getline(3), getwchar(3),
puts(3), scanf(3), ungetwc(3), unlocked_stdio(3)
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
SEE ALSO
sendmsg(2), recvmsg(2), socket(7), netlink(7), tcp(7), udp(7), raw(7), ipfw(7)
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
pthread_cond(3)
pthread_cond(3)
NAME
pthread_cond_init,
pthread_cond_destroy,
pthread_cond_signal,
pthread_cond_wait, pthread_cond_timedwait − operations on conditions
pthread_cond_broadcast,
pthread_cond(3)
pthread_cond(3)
signaled (and thus ignored) between the time a thread locks the mutex and the time it waits on the condition
variable.
pthread_cond_timedwait atomically unlocks mutex and waits on cond, as pthread_cond_wait does, but it
also bounds the duration of the wait. If cond has not been signaled within the amount of time specified by
abstime, the mutex mutex is re-acquired and pthread_cond_timedwait returns the error ETIMEDOUT.
The abstime parameter specifies an absolute time, with the same origin as time(2) and gettimeofday(2): an
abstime of 0 corresponds to 00:00:00 GMT, January 1, 1970.
SYNOPSIS
#include <pthread.h>
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_cond_destroy destroys a condition variable, freeing the resources it might hold. No threads must
be waiting on the condition variable on entrance to pthread_cond_destroy. In the LinuxThreads implementation, no resources are associated with condition variables, thus pthread_cond_destroy actually does
nothing except checking that the condition has no waiting threads.
int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr);
int pthread_cond_signal(pthread_cond_t *cond);
int pthread_cond_broadcast(pthread_cond_t *cond);
CANCELLATION
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec
*abstime);
int pthread_cond_destroy(pthread_cond_t *cond);
ASYNC-SIGNAL SAFETY
DESCRIPTION
A condition (short for ‘‘condition variable’’) is a synchronization device that allows threads to suspend
execution and relinquish the processors until some predicate on shared data is satisfied. The basic operations on conditions are: signal the condition (when the predicate becomes true), and wait for the condition,
suspending the thread execution until another thread signals the condition.
A condition variable must always be associated with a mutex, to avoid the race condition where a thread
prepares to wait on a condition variable and another thread signals the condition just before the first thread
actually waits on it.
pthread_cond_init initializes the condition variable cond, using the condition attributes specified in
cond_attr, or default attributes if cond_attr is NULL. The LinuxThreads implementation supports no
attributes for conditions, hence the cond_attr parameter is actually ignored.
Variables of type pthread_cond_t
PTHREAD_COND_INITIALIZER.
can
also
pthread_cond_wait and pthread_cond_timedwait are cancellation points. If a thread is cancelled while
suspended in one of these functions, the thread immediately resumes execution, then locks again the mutex
argument to pthread_cond_wait and pthread_cond_timedwait, and finally executes the cancellation.
Consequently, cleanup handlers are assured that mutex is locked when they are called.
be
initialized
statically,
using
the
The condition functions are not async-signal safe, and should not be called from a signal handler. In particular, calling pthread_cond_signal or pthread_cond_broadcast from a signal handler may deadlock the
calling thread.
RETURN VALUE
All condition variable functions return 0 on success and a non-zero error code on error.
ERRORS
pthread_cond_init, pthread_cond_signal, pthread_cond_broadcast, and pthread_cond_wait never
return an error code.
The pthread_cond_timedwait function returns the following error codes on error:
ETIMEDOUT
the condition variable was not signaled until the timeout specified by abstime
constant
EINTR
pthread_cond_signal restarts one of the threads that are waiting on the condition variable cond. If no
threads are waiting on cond, nothing happens. If several threads are waiting on cond, exactly one is
restarted, but it is not specified which.
pthread_cond_timedwait was interrupted by a signal
The pthread_cond_destroy function returns the following error code on error:
EBUSY
pthread_cond_broadcast restarts all the threads that are waiting on the condition variable cond. Nothing
happens if no threads are waiting on cond.
pthread_cond_wait atomically unlocks the mutex (as per pthread_unlock_mutex) and waits for the condition variable cond to be signaled. The thread execution is suspended and does not consume any CPU time
until the condition variable is signaled. The mutex must be locked by the calling thread on entrance to
pthread_cond_wait. Before returning to the calling thread, pthread_cond_wait re-acquires mutex (as per
pthread_lock_mutex).
some threads are currently waiting on cond.
AUTHOR
Xavier Leroy <[email protected]>
SEE ALSO
pthread_condattr_init(3),
nanosleep(2).
pthread_mutex_lock(3),
pthread_mutex_unlock(3),
gettimeofday(2),
Unlocking the mutex and suspending on the condition variable is done atomically. Thus, if all threads
always acquire the mutex before signaling the condition, this guarantees that the condition cannot be
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
SP/SOS1-Klausur Manual-Auszug
2009-03-27
2
pthread_create/pthread_exit(3)
pthread_create/pthread_exit(3)
NAME
pthread_mutex(3)
pthread_mutex(3)
NAME
pthread_create − create a new thread / pthread_exit − terminate the calling thread
pthread_mutex_init,
pthread_mutex_lock,
pthread_mutex_destroy − operations on mutexes
pthread_mutex_trylock,
pthread_mutex_unlock,
SYNOPSIS
#include <pthread.h>
SYNOPSIS
#include <pthread.h>
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void * (*start_routine)(void *), void *
arg);
pthread_mutex_t fastmutex = PTHREAD_MUTEX_INITIALIZER;
void pthread_exit(void *retval);
pthread_mutex_t recmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
pthread_mutex_t errchkmutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
DESCRIPTION
pthread_create creates a new thread of control that executes concurrently with the calling thread. The new
thread applies the function start_routine passing it arg as first argument. The new thread terminates either
explicitly, by calling pthread_exit(3), or implicitly, by returning from the start_routine function. The latter
case is equivalent to calling pthread_exit(3) with the result returned by start_routine as exit code.
The attr argument specifies thread attributes to be applied to the new thread. See pthread_attr_init(3) for a
complete list of thread attributes. The attr argument can also be NULL, in which case default attributes are
used: the created thread is joinable (not detached) and has default (non real-time) scheduling policy.
pthread_exit terminates the execution of the calling thread. All cleanup handlers that have been set for the
calling thread with pthread_cleanup_push(3) are executed in reverse order (the most recently pushed handler is executed first). Finalization functions for thread-specific data are then called for all keys that have
non- NULL values associated with them in the calling thread (see pthread_key_create(3)). Finally,
execution of the calling thread is stopped.
The retval argument is the return value of the thread. It can be consulted from another thread using
pthread_join(3).
RETURN VALUE
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr);
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
int pthread_mutex_destroy(pthread_mutex_t *mutex);
DESCRIPTION
A mutex is a MUTual EXclusion device, and is useful for protecting shared data structures from concurrent
modifications, and implementing critical sections and monitors.
A mutex has two possible states: unlocked (not owned by any thread), and locked (owned by one thread). A
mutex can never be owned by two different threads simultaneously. A thread attempting to lock a mutex
that is already locked by another thread is suspended until the owning thread unlocks the mutex first.
On success, the identifier of the newly created thread is stored in the location pointed by the thread argument, and a 0 is returned. On error, a non-zero error code is returned.
pthread_mutex_init initializes the mutex object pointed to by mutex according to the mutex attributes
specified in mutexattr. If mutexattr is NULL, default attributes are used instead.
The pthread_exit function never returns.
The LinuxThreads implementation supports only one mutex attributes, the mutex kind, which is either
‘‘fast’’, ‘‘recursive’’, or ‘‘error checking’’. The kind of a mutex determines whether it can be locked again
by a thread that already owns it. The default kind is ‘‘fast’’. See pthread_mutexattr_init(3) for more
information on mutex attributes.
ERRORS
EAGAIN
not enough system resources to create a process for the new thread.
Variables of type pthread_mutex_t can also be initialized statically, using the constants
PTHREAD_MUTEX_INITIALIZER (for fast mutexes), PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP (for recursive mutexes), and PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP (for error checking mutexes).
EAGAIN
more than PTHREAD_THREADS_MAX threads are already active.
pthread_mutex_lock locks the given mutex. If the mutex is currently unlocked, it becomes locked and
owned by the calling thread, and pthread_mutex_lock returns immediately. If the mutex is already locked
by another thread, pthread_mutex_lock suspends the calling thread until the mutex is unlocked.
AUTHOR
Xavier Leroy <[email protected]>
If the mutex is already locked by the calling thread, the behavior of pthread_mutex_lock depends on the
kind of the mutex. If the mutex is of the ‘‘fast’’ kind, the calling thread is suspended until the mutex is
unlocked, thus effectively causing the calling thread to deadlock. If the mutex is of the ‘‘error checking’’
kind, pthread_mutex_lock returns immediately with the error code EDEADLK. If the mutex is of the
‘‘recursive’’ kind, pthread_mutex_lock succeeds and returns immediately, recording the number of times
the calling thread has locked the mutex. An equal number of pthread_mutex_unlock operations must be
SEE ALSO
pthread_join(3), pthread_detach(3), pthread_attr_init(3).
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
pthread_mutex(3)
pthread_mutex(3)
performed before the mutex returns to the unlocked state.
socket(3)
socket(3)
NAME
socket − create an endpoint for communication
pthread_mutex_trylock behaves identically to pthread_mutex_lock, except that it does not block the
calling thread if the mutex is already locked by another thread (or by the calling thread in the case of a
‘‘fast’’ mutex). Instead, pthread_mutex_trylock returns immediately with the error code EBUSY.
pthread_mutex_unlock unlocks the given mutex. The mutex is assumed to be locked and owned by the
calling thread on entrance to pthread_mutex_unlock. If the mutex is of the ‘‘fast’’ kind,
pthread_mutex_unlock always returns it to the unlocked state. If it is of the ‘‘recursive’’ kind, it decrements the locking count of the mutex (number of pthread_mutex_lock operations performed on it by the
calling thread), and only when this count reaches zero is the mutex actually unlocked.
On ‘‘error checking’’ mutexes, pthread_mutex_unlock actually checks at run-time that the mutex is
locked on entrance, and that it was locked by the same thread that is now calling pthread_mutex_unlock.
If these conditions are not met, an error code is returned and the mutex remains unchanged. ‘‘Fast’’ and
‘‘recursive’’ mutexes perform no such checks, thus allowing a locked mutex to be unlocked by a thread
other than its owner. This is non-portable behavior and must not be relied upon.
pthread_mutex_destroy destroys a mutex object, freeing the resources it might hold. The mutex must be
unlocked on entrance. In the LinuxThreads implementation, no resources are associated with mutex objects,
thus pthread_mutex_destroy actually does nothing except checking that the mutex is unlocked.
RETURN VALUE
pthread_mutex_init always returns 0. The other mutex functions return 0 on success and a non-zero error
code on error.
ERRORS
The pthread_mutex_lock function returns the following error code on error:
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
DESCRIPTION
socket( ) creates an endpoint for communication and returns a descriptor.
The domain parameter specifies a communications domain within which communication will take place;
this selects the protocol family which should be used. The protocol family generally is the same as the
address family for the addresses supplied in later operations on the socket. The currently understood formats are:
PF_INET
ARPA Internet protocols
The socket has the indicated type, which specifies the communication semantics. Currently defined types
are:
SOCK_STREAM
SOCK_DGRAM
A SOCK_STREAM type provides sequenced, reliable, two-way connection-based byte streams. An out-ofband data transmission mechanism may be supported. A SOCK_DGRAM socket supports datagrams (connectionless, unreliable messages of a fixed (typically small) maximum length).
protocol specifies a particular protocol to be used with the socket. Normally only a single protocol exists to
support a particular socket type within a given protocol family. However, multiple protocols may exist, in
which case a particular protocol must be specified in this manner. The protocol number to use is particular
to the “communication domain” in which communication is to take place. If a protocol is specified by the
caller, then it will be packaged into a socket level option request and sent to the underlying protocol layers.
Sockets of type SOCK_STREAM are full-duplex byte streams, similar to pipes. A stream socket must be in
a connected state before any data may be sent or received on it. A connection to another socket is created
with a connect(3N) call. Once connected, data may be transferred using read(2) and write(2) calls or
some variant of the send(3N) and recv(3N) calls. When a session has been completed, a close(2) may be
performed. Out-of-band data may also be transmitted as described on the send(3N) manual page and
received as described on the recv(3N) manual page.
EINVAL
the mutex has not been properly initialized.
EDEADLK
the mutex is already locked by the calling thread (‘‘error checking’’ mutexes only).
The communications protocols used to implement a SOCK_STREAM insure that data is not lost or duplicated. If a piece of data for which the peer protocol has buffer space cannot be successfully transmitted
within a reasonable length of time, then the connection is considered broken and calls will indicate an error
with −1 returns and with ETIMEDOUT as the specific code in the global variable errno. A SIGPIPE signal
is raised if a process sends on a broken stream; this causes naive processes, which do not handle the signal,
to exit.
The pthread_mutex_unlock function returns the following error code on error:
EINVAL
the mutex has not been properly initialized.
EPERM
the calling thread does not own the mutex (‘‘error checking’’ mutexes only).
RETURN VALUES
A −1 is returned if an error occurs. Otherwise the return value is a descriptor referencing the socket.
The pthread_mutex_destroy function returns the following error code on error:
ERRORS
EBUSY
The socket( ) call fails if:
the mutex is currently locked.
EACCES
AUTHOR
Xavier Leroy <[email protected]>
The per-process descriptor table is full.
ENOMEM
Insufficient user memory is available.
SEE ALSO
SEE ALSO
close(2), read(2), write(2), accept(3N), bind(3N), connect(3N), listen(3N),
pthread_mutexattr_init(3), pthread_mutexattr_setkind_np(3), pthread_cancel(3).
SP/SOS1-Klausur Manual-Auszug
Permission to create a socket of the specified type and/or protocol is denied.
EMFILE
2009-03-27
2
SP/SOS1-Klausur Manual-Auszug
2009-03-27
1
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement