source: roaraudio/libroar/vio_winsock.c @ 6052:d48765b2475e

Last change on this file since 6052:d48765b2475e was 6052:d48765b2475e, checked in by phi, 9 years ago

updated copyright headers

File size: 4.1 KB
Line 
1//vio_winsock.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2015
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
39
40static int _get_fh(struct roar_vio_calls * vio) {
41 int fh;
42
43 if ( roar_vio_basic_ctl(vio, ROAR_VIO_CTL_GET_FH, &fh) == -1 )
44  return -1;
45
46 return fh;
47}
48
49ssize_t roar_vio_winsock_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
50 ssize_t ret;
51
52 roar_err_clear_all();
53 ret = recv(_get_fh(vio), buf, count, 0);
54 roar_err_update();
55
56 return ret;
57}
58
59ssize_t roar_vio_winsock_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
60 ssize_t ret;
61
62 roar_err_clear_all();
63 ret = send(_get_fh(vio), buf, count, 0);
64 roar_err_update();
65
66 return ret;
67}
68
69int     roar_vio_winsock_sync    (struct roar_vio_calls * vio) {
70 return 0;
71}
72
73int     roar_vio_winsock_ctl     (struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) {
74 int tmp;
75 int s_r = 0, s_w = 0;
76
77 if ( vio == NULL || cmd == -1 )
78  return -1;
79
80 ROAR_DBG("roar_vio_winsock_ctl(vio=%p, cmd=0x%.8x, data=%p) = ?", vio, cmd, data);
81
82 switch (cmd) {
83  case ROAR_VIO_CTL_GET_NAME:
84    if ( data == NULL ) {
85     roar_err_set(ROAR_ERROR_FAULT);
86     return -1;
87    }
88
89    *(char**)data = "winsock";
90    return 0;
91   break;
92  case ROAR_VIO_CTL_GET_SELECT_FH:
93  case ROAR_VIO_CTL_GET_SELECT_READ_FH:
94  case ROAR_VIO_CTL_GET_SELECT_WRITE_FH:
95    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, _get_fh(vio));
96    *(int*)data = _get_fh(vio);
97    return 0;
98   break;
99  case ROAR_VIO_CTL_SET_NOSYNC:
100    vio->sync = NULL;
101    return 0;
102   break;
103  case ROAR_VIO_CTL_ACCEPT:
104    roar_err_clear_all();
105    tmp = accept(_get_fh(vio), NULL, 0);
106    roar_err_update();
107    if ( tmp == -1 )
108     return -1;
109
110    // most proably a socket.
111    if ( roar_vio_open_fh_socket(data, tmp) == -1 ) {
112     closesocket(tmp);
113     return -1;
114    }
115
116    return 0;
117   break;
118  case ROAR_VIO_CTL_SHUTDOWN:
119    tmp = *(int*)data;
120
121    if ( tmp & ROAR_VIO_SHUTDOWN_READ ) {
122     s_r = 1;
123     tmp -= ROAR_VIO_SHUTDOWN_READ;
124    }
125
126    if ( tmp & ROAR_VIO_SHUTDOWN_WRITE ) {
127     s_w = 1;
128     tmp -= ROAR_VIO_SHUTDOWN_WRITE;
129    }
130
131    if ( tmp != 0 ) { /* we currently only support R and W shutdowns */
132     roar_err_set(ROAR_ERROR_NOSYS);
133     return -1;
134    }
135
136    if ( s_r && s_w ) {
137     tmp = SHUT_RDWR;
138    } else if ( s_r ) {
139     tmp = SHUT_RD;
140    } else if ( s_w ) {
141     tmp = SHUT_WR;
142    } else {
143     return 0; // nothing to do.
144    }
145
146    return shutdown(_get_fh(vio), tmp);
147   break;
148  case ROAR_VIO_CTL_GET_SOCKNAME:
149  case ROAR_VIO_CTL_GET_PEERNAME:
150    return roar_vio_basic_ctl(vio, cmd, data);
151   break;
152 }
153
154 roar_err_set(ROAR_ERROR_BADRQC);
155 return -1;
156}
157
158int     roar_vio_winsock_close   (struct roar_vio_calls * vio) {
159
160 closesocket(_get_fh(vio));
161
162 return 0;
163}
164#endif
165
166//ll
Note: See TracBrowser for help on using the repository browser.