source: roaraudio/libroar/vio_winsock.c @ 5254:4b808f2c219c

Last change on this file since 5254:4b808f2c219c was 4708:c9d40761088a, checked in by phi, 13 years ago

updated copyright statements

File size: 3.7 KB
Line 
1//vio_winsock.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011
5 *
6 *  This file is part of libroar a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroar is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
38#ifdef ROAR_TARGET_WIN32
39ssize_t roar_vio_winsock_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
40 return recv(roar_vio_get_fh(vio), buf, count, 0);
41}
42
43ssize_t roar_vio_winsock_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
44 return send(roar_vio_get_fh(vio), buf, count, 0);
45}
46
47int     roar_vio_winsock_nonblock(struct roar_vio_calls * vio, int state) {
48 return -1;
49}
50int     roar_vio_winsock_sync    (struct roar_vio_calls * vio) {
51 return 0;
52}
53
54int     roar_vio_winsock_ctl     (struct roar_vio_calls * vio, int cmd, void * data) {
55 int tmp;
56 int s_r = 0, s_w = 0;
57
58 if ( vio == NULL || cmd == -1 )
59  return -1;
60
61 ROAR_DBG("roar_vio_winsock_ctl(vio=%p, cmd=0x%.8x, data=%p) = ?", vio, cmd, data);
62
63 switch (cmd) {
64  case ROAR_VIO_CTL_GET_NAME:
65    if ( data == NULL )
66     return -1;
67
68    *(char**)data = "winsock";
69    return 0;
70   break;
71  case ROAR_VIO_CTL_GET_SELECT_FH:
72  case ROAR_VIO_CTL_GET_SELECT_READ_FH:
73  case ROAR_VIO_CTL_GET_SELECT_WRITE_FH:
74    ROAR_DBG("roar_vio_winsock_ctl(vio=%p, cmd=ROAR_VIO_CTL_GET_SELECT_*FH(0x%.8x), data=%p) = 0 // fh=%i", vio, cmd, data, roar_vio_get_fh(vio));
75    *(int*)data = roar_vio_get_fh(vio);
76    return 0;
77   break;
78  case ROAR_VIO_CTL_SET_NOSYNC:
79    vio->sync = NULL;
80    return 0;
81   break;
82  case ROAR_VIO_CTL_ACCEPT:
83    tmp = accept(roar_vio_get_fh(vio), NULL, 0);
84    if ( tmp == -1 )
85     return -1;
86
87    // most proably a socket.
88    if ( roar_vio_open_fh_socket(data, tmp) == -1 ) {
89     closesocket(tmp);
90     return -1;
91    }
92
93    return 0;
94   break;
95  case ROAR_VIO_CTL_SHUTDOWN:
96    tmp = *(int*)data;
97
98    if ( tmp & ROAR_VIO_SHUTDOWN_READ ) {
99     s_r = 1;
100     tmp -= ROAR_VIO_SHUTDOWN_READ;
101    }
102
103    if ( tmp & ROAR_VIO_SHUTDOWN_WRITE ) {
104     s_w = 1;
105     tmp -= ROAR_VIO_SHUTDOWN_WRITE;
106    }
107
108    if ( tmp != 0 ) /* we currently only support R and W shutdowns */
109     return -1;
110
111    if ( s_r && s_w ) {
112     tmp = SHUT_RDWR;
113    } else if ( s_r ) {
114     tmp = SHUT_RD;
115    } else if ( s_w ) {
116     tmp = SHUT_WR;
117    } else {
118     return 0; // nothing to do.
119    }
120
121    return shutdown(roar_vio_get_fh(vio), tmp);
122   break;
123 }
124
125 return -1;
126}
127
128int     roar_vio_winsock_close   (struct roar_vio_calls * vio) {
129
130 closesocket(roar_vio_get_fh(vio));
131
132 return 0;
133}
134#endif
135
136//ll
Note: See TracBrowser for help on using the repository browser.