source: roaraudio/libroar/vio_winsock.c @ 5289:ddb3677af4d0

Last change on this file since 5289:ddb3677af4d0 was 5278:b3e0dd3f3141, checked in by phi, 12 years ago

last parts of merging _nonblock into _ctl and fixed sizeof(cmd) of _ctls

File size: 3.6 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_sync    (struct roar_vio_calls * vio) {
48 return 0;
49}
50
51int     roar_vio_winsock_ctl     (struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) {
52 int tmp;
53 int s_r = 0, s_w = 0;
54
55 if ( vio == NULL || cmd == -1 )
56  return -1;
57
58 ROAR_DBG("roar_vio_winsock_ctl(vio=%p, cmd=0x%.8x, data=%p) = ?", vio, cmd, data);
59
60 switch (cmd) {
61  case ROAR_VIO_CTL_GET_NAME:
62    if ( data == NULL )
63     return -1;
64
65    *(char**)data = "winsock";
66    return 0;
67   break;
68  case ROAR_VIO_CTL_GET_SELECT_FH:
69  case ROAR_VIO_CTL_GET_SELECT_READ_FH:
70  case ROAR_VIO_CTL_GET_SELECT_WRITE_FH:
71    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));
72    *(int*)data = roar_vio_get_fh(vio);
73    return 0;
74   break;
75  case ROAR_VIO_CTL_SET_NOSYNC:
76    vio->sync = NULL;
77    return 0;
78   break;
79  case ROAR_VIO_CTL_ACCEPT:
80    tmp = accept(roar_vio_get_fh(vio), NULL, 0);
81    if ( tmp == -1 )
82     return -1;
83
84    // most proably a socket.
85    if ( roar_vio_open_fh_socket(data, tmp) == -1 ) {
86     closesocket(tmp);
87     return -1;
88    }
89
90    return 0;
91   break;
92  case ROAR_VIO_CTL_SHUTDOWN:
93    tmp = *(int*)data;
94
95    if ( tmp & ROAR_VIO_SHUTDOWN_READ ) {
96     s_r = 1;
97     tmp -= ROAR_VIO_SHUTDOWN_READ;
98    }
99
100    if ( tmp & ROAR_VIO_SHUTDOWN_WRITE ) {
101     s_w = 1;
102     tmp -= ROAR_VIO_SHUTDOWN_WRITE;
103    }
104
105    if ( tmp != 0 ) /* we currently only support R and W shutdowns */
106     return -1;
107
108    if ( s_r && s_w ) {
109     tmp = SHUT_RDWR;
110    } else if ( s_r ) {
111     tmp = SHUT_RD;
112    } else if ( s_w ) {
113     tmp = SHUT_WR;
114    } else {
115     return 0; // nothing to do.
116    }
117
118    return shutdown(roar_vio_get_fh(vio), tmp);
119   break;
120 }
121
122 roar_err_set(ROAR_ERROR_BADRQC);
123 return -1;
124}
125
126int     roar_vio_winsock_close   (struct roar_vio_calls * vio) {
127
128 closesocket(roar_vio_get_fh(vio));
129
130 return 0;
131}
132#endif
133
134//ll
Note: See TracBrowser for help on using the repository browser.