XMMS2
src/lib/xmmssocket/socket_unix.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include "xmmsc/xmmsc_sockets.h"
00003 
00004 
00005 int xmms_sockets_initialize () {
00006     return 1;
00007 }
00008 
00009 /**
00010  * Tries to set socket to non-blocking mode.
00011  * @param socket Socket to make non-blocking.
00012  * On success, returns 1.
00013  * On failure, closes socket and returns 0.
00014  */
00015 int xmms_socket_set_nonblock (xmms_socket_t socket) {
00016 
00017     int flags;
00018     flags = fcntl (socket, F_GETFL, 0);
00019 
00020     if (flags == -1) {
00021         close (socket);
00022         return 0;
00023     }
00024 
00025     flags |= O_NONBLOCK;
00026 
00027     flags = fcntl (socket, F_SETFL, flags);
00028     if (flags == -1) {
00029         close (socket);
00030         return 0;
00031     }
00032     return 1;
00033 }
00034 
00035 
00036 int xmms_socket_valid (xmms_socket_t socket) {
00037     if (socket < 0) {
00038         return 0;
00039     }
00040     return 1;
00041 }
00042 
00043 void xmms_socket_invalidate (xmms_socket_t *socket) {
00044     *socket = -1;
00045 }
00046 
00047 void xmms_socket_close (xmms_socket_t socket) {
00048     close (socket);
00049 }
00050 
00051 int xmms_socket_errno () {
00052     return errno;
00053 }