JackNetUnixSocket.cpp 16 KB
Newer Older
sletz's avatar
sletz committed
1
/*
sletz's avatar
sletz committed
2
Copyright (C) 2008-2011 Romain Moret at Grame
sletz's avatar
sletz committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include "JackNetUnixSocket.h"
sletz's avatar
sletz committed
21
22
#include "JackError.h"

sletz's avatar
sletz committed
23
24
#include <unistd.h>
#include <fcntl.h>
sletz's avatar
sletz committed
25

Stephane Letz's avatar
Stephane Letz committed
26
27
using namespace std;

sletz's avatar
sletz committed
28
namespace Jack
29
30
{
    //utility *********************************************************************************************************
Stephane Letz's avatar
Stephane Letz committed
31
    int GetHostName(char * name, int size)
32
    {
Stephane Letz's avatar
Stephane Letz committed
33
34
35
        if (gethostname(name, size) == SOCKET_ERROR) {
            jack_error("Can't get 'hostname' : %s", strerror(NET_ERROR_CODE));
            strcpy(name, "default");
moret's avatar
moret committed
36
            return SOCKET_ERROR;
37
38
39
40
41
42
43
44
        }
        return 0;
    }

    //construct/destruct***********************************************************************************************
    JackNetUnixSocket::JackNetUnixSocket()
    {
        fSockfd = 0;
moret's avatar
moret committed
45
        fPort = 0;
sletz's avatar
sletz committed
46
        fTimeOut = 0;
47
        fSendAddr.sin_family = AF_INET;
Stephane Letz's avatar
Stephane Letz committed
48
49
        fSendAddr.sin_addr.s_addr = htonl(INADDR_ANY);
        memset(&fSendAddr.sin_zero, 0, 8);
50
        fRecvAddr.sin_family = AF_INET;
Stephane Letz's avatar
Stephane Letz committed
51
52
        fRecvAddr.sin_addr.s_addr = htonl(INADDR_ANY);
        memset(&fRecvAddr.sin_zero, 0, 8);
53
54
    }

Stephane Letz's avatar
Stephane Letz committed
55
    JackNetUnixSocket::JackNetUnixSocket(const char* ip, int port)
56
57
58
    {
        fSockfd = 0;
        fPort = port;
sletz's avatar
sletz committed
59
        fTimeOut = 0;
60
        fSendAddr.sin_family = AF_INET;
Stephane Letz's avatar
Stephane Letz committed
61
62
63
        fSendAddr.sin_port = htons(port);
        inet_aton(ip, &fSendAddr.sin_addr);
        memset(&fSendAddr.sin_zero, 0, 8);
64
        fRecvAddr.sin_family = AF_INET;
Stephane Letz's avatar
Stephane Letz committed
65
66
67
        fRecvAddr.sin_port = htons(port);
        fRecvAddr.sin_addr.s_addr = htonl(INADDR_ANY);
        memset(&fRecvAddr.sin_zero, 0, 8);
68
69
    }

Stephane Letz's avatar
Stephane Letz committed
70
    JackNetUnixSocket::JackNetUnixSocket(const JackNetUnixSocket& socket)
71
    {
72
        fSockfd = 0;
sletz's avatar
sletz committed
73
        fTimeOut = 0;
74
75
76
77
78
        fPort = socket.fPort;
        fSendAddr = socket.fSendAddr;
        fRecvAddr = socket.fRecvAddr;
    }

79
80
81
82
83
    JackNetUnixSocket::~JackNetUnixSocket()
    {
        Close();
    }

Stephane Letz's avatar
Stephane Letz committed
84
    JackNetUnixSocket& JackNetUnixSocket::operator=(const JackNetUnixSocket& socket)
85
    {
Stephane Letz's avatar
Stephane Letz committed
86
        if (this != &socket) {
87
88
89
90
91
            fSockfd = 0;
            fPort = socket.fPort;
            fSendAddr = socket.fSendAddr;
            fRecvAddr = socket.fRecvAddr;
        }
92
        return *this;
93
94
    }

95
96
97
    //socket***********************************************************************************************************
    int JackNetUnixSocket::NewSocket()
    {
Stephane Letz's avatar
Stephane Letz committed
98
        if (fSockfd) {
99
100
101
            Close();
            Reset();
        }
Stephane Letz's avatar
Stephane Letz committed
102
        fSockfd = socket(AF_INET, SOCK_DGRAM, 0);
sletz's avatar
sletz committed
103

sletz's avatar
sletz committed
104
105
        /* Enable address reuse */
        int res, on = 1;
sletz's avatar
sletz committed
106
    #ifdef __APPLE__
107
        if ((res = setsockopt(fSockfd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on))) < 0) {
sletz's avatar
sletz committed
108
109
110
    #else
        if ((res = setsockopt(fSockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) < 0) {
    #endif
sletz's avatar
sletz committed
111
112
            StrError(NET_ERROR_CODE);
        }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
        
        int tos = 0;       /* see <netinet/in.h> */
        
        /*
        DSCP Field Hex/Bin/Dec	Layer 2 Prio	Traffic Type	Acronym	WMM Access Category
        0x38 / 111000 / 56	7	Network Control	NC	AC_VO
        0x30 / 110000 / 48	6	Voice	VO	AC_VO
        0x28 / 101000 / 40	5	Video	VI	AC_VI
        0x20 / 100000 / 32	4	Controlled Load	CL	AC_VI
        0x18 / 011000 / 24	3	Excellent Effort	EE	AC_BE
        0x10 / 010000 / 16	2	Spare	--	AC_BK
        0x08 / 001000 / 8	1	Background	BK	AC_BK
        0x00 / 000000 / 0	0	Best Effort	BE	AC_BE
        */
        
        /*
        socklen_t len = sizeof(tos);
        
        res = getsockopt(fSockfd, IPPROTO_IP, IP_TOS, &tos, &len);
        printf("getsockopt IPPROTO_IP res = %d  tos = %d\n", res, tos);
        
        tos = 46 * 4;       // see <netinet/in.h> 
        res = setsockopt(fSockfd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
        
        printf("setsockopt IPPROTO_IP res = %d  tos = %d\n", res, tos );
        
        res = getsockopt(fSockfd, IPPROTO_IP, IP_TOS, &tos, &len);
        printf("getsockopt IPPROTO_IP res = %d  tos = %d\n", res, tos);
        */
  
143
144
145
        return fSockfd;
    }

Stephane Letz's avatar
Stephane Letz committed
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
    bool JackNetUnixSocket::IsLocal(char* ip)
    {
        if (strcmp(ip, "127.0.0.1") == 0) {
            return true;
        }

        char host_name[32];
        gethostname(host_name, sizeof(host_name));

        struct hostent* host = gethostbyname(host_name);
        if (host) {
            for (int i = 0; host->h_addr_list[i] != 0; ++i) {
                struct in_addr addr;
                memcpy(&addr, host->h_addr_list[i], sizeof(struct in_addr));
                if (strcmp(inet_ntoa(addr), ip) == 0) {
                    return true;
                }
            }
            return false;
        } else {
            return false;
        }
    }

170
171
    int JackNetUnixSocket::Bind()
    {
Stephane Letz's avatar
Stephane Letz committed
172
        return bind(fSockfd, reinterpret_cast<socket_address_t*>(&fRecvAddr), sizeof(socket_address_t));
173
174
    }

Stephane Letz's avatar
Stephane Letz committed
175
    int JackNetUnixSocket::BindWith(const char* ip)
176
    {
Stephane Letz's avatar
Stephane Letz committed
177
        int addr_conv = inet_aton(ip, &fRecvAddr.sin_addr);
Stephane Letz's avatar
Stephane Letz committed
178
        if (addr_conv < 0) {
179
            return addr_conv;
Stephane Letz's avatar
Stephane Letz committed
180
        }
181
182
183
        return Bind();
    }

Stephane Letz's avatar
Stephane Letz committed
184
    int JackNetUnixSocket::BindWith(int port)
185
    {
Stephane Letz's avatar
Stephane Letz committed
186
        fRecvAddr.sin_port = htons(port);
187
188
189
190
191
        return Bind();
    }

    int JackNetUnixSocket::Connect()
    {
Stephane Letz's avatar
Stephane Letz committed
192
        return connect(fSockfd, reinterpret_cast<socket_address_t*>(&fSendAddr), sizeof(socket_address_t));
193
194
    }

Stephane Letz's avatar
Stephane Letz committed
195
    int JackNetUnixSocket::ConnectTo(const char* ip)
196
    {
Stephane Letz's avatar
Stephane Letz committed
197
        int addr_conv = inet_aton(ip, &fSendAddr.sin_addr);
Stephane Letz's avatar
Stephane Letz committed
198
        if (addr_conv < 0) {
199
            return addr_conv;
Stephane Letz's avatar
Stephane Letz committed
200
        }
201
202
203
204
205
        return Connect();
    }

    void JackNetUnixSocket::Close()
    {
Stephane Letz's avatar
Stephane Letz committed
206
        if (fSockfd) {
Stephane Letz's avatar
Stephane Letz committed
207
            close(fSockfd);
Stephane Letz's avatar
Stephane Letz committed
208
        }
209
210
211
212
213
214
        fSockfd = 0;
    }

    void JackNetUnixSocket::Reset()
    {
        fSendAddr.sin_family = AF_INET;
Stephane Letz's avatar
Stephane Letz committed
215
216
217
        fSendAddr.sin_port = htons(fPort);
        fSendAddr.sin_addr.s_addr = htonl(INADDR_ANY);
        memset(&fSendAddr.sin_zero, 0, 8);
218
        fRecvAddr.sin_family = AF_INET;
Stephane Letz's avatar
Stephane Letz committed
219
220
221
        fRecvAddr.sin_port = htons(fPort);
        fRecvAddr.sin_addr.s_addr = htonl(INADDR_ANY);
        memset(&fRecvAddr.sin_zero, 0, 8);
222
223
224
225
    }

    bool JackNetUnixSocket::IsSocket()
    {
Stephane Letz's avatar
Stephane Letz committed
226
        return(fSockfd) ? true : false;
227
228
229
    }

    //IP/PORT***********************************************************************************************************
Stephane Letz's avatar
Stephane Letz committed
230
    void JackNetUnixSocket::SetPort(int port)
231
232
    {
        fPort = port;
Stephane Letz's avatar
Stephane Letz committed
233
234
        fSendAddr.sin_port = htons(port);
        fRecvAddr.sin_port = htons(port);
235
236
237
238
239
240
241
242
    }

    int JackNetUnixSocket::GetPort()
    {
        return fPort;
    }

    //address***********************************************************************************************************
Stephane Letz's avatar
Stephane Letz committed
243
    int JackNetUnixSocket::SetAddress(const char* ip, int port)
244
    {
Stephane Letz's avatar
Stephane Letz committed
245
        int addr_conv = inet_aton(ip, &fSendAddr.sin_addr);
Stephane Letz's avatar
Stephane Letz committed
246
        if (addr_conv < 0) {
247
            return addr_conv;
Stephane Letz's avatar
Stephane Letz committed
248
        }
Stephane Letz's avatar
Stephane Letz committed
249
        fSendAddr.sin_port = htons(port);
250
251
252
253
254
        return 0;
    }

    char* JackNetUnixSocket::GetSendIP()
    {
Stephane Letz's avatar
Stephane Letz committed
255
        return inet_ntoa(fSendAddr.sin_addr);
256
257
258
259
    }

    char* JackNetUnixSocket::GetRecvIP()
    {
Stephane Letz's avatar
Stephane Letz committed
260
        return inet_ntoa(fRecvAddr.sin_addr);
261
262
263
    }

    //utility************************************************************************************************************
Stephane Letz's avatar
Stephane Letz committed
264
    int JackNetUnixSocket::GetName(char* name)
265
    {
Stephane Letz's avatar
Stephane Letz committed
266
        return gethostname(name, 255);
267
268
    }

Stephane Letz's avatar
Stephane Letz committed
269
    int JackNetUnixSocket::JoinMCastGroup(const char* ip)
270
271
    {
        struct ip_mreq multicast_req;
Stephane Letz's avatar
Stephane Letz committed
272
273
274
        inet_aton(ip, &multicast_req.imr_multiaddr);
        multicast_req.imr_interface.s_addr = htonl(INADDR_ANY);
        return SetOption(IPPROTO_IP, IP_ADD_MEMBERSHIP, &multicast_req, sizeof(multicast_req));
275
276
277
    }

    //options************************************************************************************************************
Stephane Letz's avatar
Stephane Letz committed
278
    int JackNetUnixSocket::SetOption(int level, int optname, const void* optval, socklen_t optlen)
279
    {
Stephane Letz's avatar
Stephane Letz committed
280
        return setsockopt(fSockfd, level, optname, optval, optlen);
281
282
    }

Stephane Letz's avatar
Stephane Letz committed
283
    int JackNetUnixSocket::GetOption(int level, int optname, void* optval, socklen_t* optlen)
284
    {
Stephane Letz's avatar
Stephane Letz committed
285
        return getsockopt(fSockfd, level, optname, optval, optlen);
286
287
    }

moret's avatar
moret committed
288
    //timeout************************************************************************************************************
sletz's avatar
sletz committed
289
290

#if defined(__sun__) || defined(sun)
Stephane Letz's avatar
Stephane Letz committed
291
    int JackNetUnixSocket::SetTimeOut(int us)
sletz's avatar
sletz committed
292
293
294
    {
        int	flags;
        fTimeOut = us;
sletz's avatar
sletz committed
295

sletz's avatar
sletz committed
296
297
298
299
        if ((flags = fcntl(fSockfd, F_GETFL, 0)) < 0) {
		    jack_error("JackNetUnixSocket::SetTimeOut error in fcntl F_GETFL");
		    return -1;
	    }
sletz's avatar
sletz committed
300

sletz's avatar
sletz committed
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
	    flags |= O_NONBLOCK;
	    if (fcntl(fSockfd, F_SETFL, flags) < 0) {
		    jack_error("JackNetUnixSocket::SetTimeOut error in fcntl F_SETFL");
		    return 1;
	    }

        return 0;
    }

    int JackNetUnixSocket::WaitRead()
    {
        if (fTimeOut > 0) {

            struct timeval tv;
	        fd_set fdset;
            ssize_t	res;
sletz's avatar
sletz committed
317

sletz's avatar
sletz committed
318
319
            tv.tv_sec = fTimeOut / 1000000;
	        tv.tv_usec = fTimeOut % 1000000;
sletz's avatar
sletz committed
320

sletz's avatar
sletz committed
321
322
	        FD_ZERO(&fdset);
	        FD_SET(fSockfd, &fdset);
sletz's avatar
sletz committed
323

sletz's avatar
sletz committed
324
325
	        do {
		        res = select(fSockfd + 1, &fdset, NULL, NULL, &tv);
Stephane Letz's avatar
Stephane Letz committed
326
	        } while (res < 0 && errno == EINTR);
sletz's avatar
sletz committed
327

sletz's avatar
sletz committed
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
	        if (res < 0) {
 		        return res;
            } else if (res == 0) {
                errno = ETIMEDOUT;
		        return -1;
	        }
        }

        return 0;
    }

    int JackNetUnixSocket::WaitWrite()
    {
        if (fTimeOut > 0) {

            struct timeval tv;
	        fd_set fdset;
            ssize_t	res;
sletz's avatar
sletz committed
346

sletz's avatar
sletz committed
347
            tv.tv_sec = fTimeOut / 1000000;
sletz's avatar
sletz committed
348
349
            tv.tv_usec = fTimeOut % 1000000;

sletz's avatar
sletz committed
350
351
	        FD_ZERO(&fdset);
	        FD_SET(fSockfd, &fdset);
sletz's avatar
sletz committed
352

sletz's avatar
sletz committed
353
354
	        do {
		        res = select(fSockfd + 1, NULL, &fdset, NULL, &tv);
Stephane Letz's avatar
Stephane Letz committed
355
	        } while (res < 0 && errno == EINTR);
sletz's avatar
sletz committed
356

sletz's avatar
sletz committed
357
358
359
360
361
362
363
364
365
366
367
368
	        if (res < 0) {
		        return res;
            } else if (res == 0) {
                errno = ETIMEDOUT;
		        return -1;
	        }
        }

        return 0;
    }

#else
Stephane Letz's avatar
Stephane Letz committed
369
    int JackNetUnixSocket::SetTimeOut(int us)
370
    {
Stephane Letz's avatar
Stephane Letz committed
371
        jack_log("JackNetUnixSocket::SetTimeout %d usecs", us);
372
        struct timeval timeout;
moret's avatar
moret committed
373

374
        //less than 1 sec
Stephane Letz's avatar
Stephane Letz committed
375
        if (us < 1000000) {
376
            timeout.tv_sec = 0;
moret's avatar
moret committed
377
            timeout.tv_usec = us;
Stephane Letz's avatar
Stephane Letz committed
378
        } else {
379
        //more than 1 sec
380
381
382
383
            float sec = float(us) / 1000000.f;
            timeout.tv_sec = (int)sec;
            float usec = (sec - float(timeout.tv_sec)) * 1000000;
            timeout.tv_usec =(int)usec;
384
        }
Stephane Letz's avatar
Stephane Letz committed
385
        return SetOption(SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
386
    }
sletz's avatar
sletz committed
387
#endif
388
389
390
391
392

    //local loop**********************************************************************************************************
    int JackNetUnixSocket::SetLocalLoop()
    {
        char disable = 0;
Stephane Letz's avatar
Stephane Letz committed
393
        return SetOption(IPPROTO_IP, IP_MULTICAST_LOOP, &disable, sizeof(disable));
394
395
396
    }

    //network operations**************************************************************************************************
Stephane Letz's avatar
Stephane Letz committed
397
    int JackNetUnixSocket::SendTo(const void* buffer, size_t nbytes, int flags)
398
    {
sletz's avatar
sletz committed
399
    #if defined(__sun__) || defined(sun)
Stephane Letz's avatar
Stephane Letz committed
400
        if (WaitWrite() < 0) {
sletz's avatar
sletz committed
401
            return -1;
Stephane Letz's avatar
Stephane Letz committed
402
        }
sletz's avatar
sletz committed
403
    #endif
404
405
406
407
408
        int res;
        if ((res = sendto(fSockfd, buffer, nbytes, flags, reinterpret_cast<socket_address_t*>(&fSendAddr), sizeof(socket_address_t))) < 0) {
            jack_error("SendTo fd = %ld err = %s", fSockfd, strerror(errno));
        }
        return res;
409
410
    }

Stephane Letz's avatar
Stephane Letz committed
411
    int JackNetUnixSocket::SendTo(const void* buffer, size_t nbytes, int flags, const char* ip)
412
    {
Stephane Letz's avatar
Stephane Letz committed
413
        int addr_conv = inet_aton(ip, &fSendAddr.sin_addr);
414
        if (addr_conv < 1) {
415
            return addr_conv;
416
        }
417
        fSendAddr.sin_port = htons(fPort);
sletz's avatar
sletz committed
418
    #if defined(__sun__) || defined(sun)
Stephane Letz's avatar
Stephane Letz committed
419
        if (WaitWrite() < 0) {
sletz's avatar
sletz committed
420
            return -1;
Stephane Letz's avatar
Stephane Letz committed
421
        }
sletz's avatar
sletz committed
422
    #endif
Stephane Letz's avatar
Stephane Letz committed
423
        return SendTo(buffer, nbytes, flags);
424
425
    }

Stephane Letz's avatar
Stephane Letz committed
426
    int JackNetUnixSocket::Send(const void* buffer, size_t nbytes, int flags)
427
    {
sletz's avatar
sletz committed
428
    #if defined(__sun__) || defined(sun)
Stephane Letz's avatar
Stephane Letz committed
429
        if (WaitWrite() < 0) {
sletz's avatar
sletz committed
430
            return -1;
Stephane Letz's avatar
Stephane Letz committed
431
        }
sletz's avatar
sletz committed
432
    #endif
433
434
435
436
437
        int res;
        if ((res = send(fSockfd, buffer, nbytes, flags)) < 0) {
            jack_error("Send fd = %ld err = %s", fSockfd, strerror(errno));
        }
        return res;
438
439
    }

Stephane Letz's avatar
Stephane Letz committed
440
    int JackNetUnixSocket::RecvFrom(void* buffer, size_t nbytes, int flags)
441
    {
Stephane Letz's avatar
Stephane Letz committed
442
        socklen_t addr_len = sizeof(socket_address_t);
sletz's avatar
sletz committed
443
    #if defined(__sun__) || defined(sun)
Stephane Letz's avatar
Stephane Letz committed
444
        if (WaitRead() < 0) {
sletz's avatar
sletz committed
445
            return -1;
Stephane Letz's avatar
Stephane Letz committed
446
        }
sletz's avatar
sletz committed
447
    #endif
448
449
450
451
452
        int res;
        if ((res = recvfrom(fSockfd, buffer, nbytes, flags, reinterpret_cast<socket_address_t*>(&fRecvAddr), &addr_len)) < 0) {
            jack_error("RecvFrom fd = %ld err = %s", fSockfd, strerror(errno));
        }
        return res;        
453
454
    }

Stephane Letz's avatar
Stephane Letz committed
455
    int JackNetUnixSocket::Recv(void* buffer, size_t nbytes, int flags)
456
    {
sletz's avatar
sletz committed
457
    #if defined(__sun__) || defined(sun)
Stephane Letz's avatar
Stephane Letz committed
458
        if (WaitRead() < 0) {
sletz's avatar
sletz committed
459
            return -1;
Stephane Letz's avatar
Stephane Letz committed
460
        }
sletz's avatar
sletz committed
461
    #endif
462
463
464
465
466
        int res;
        if ((res = recv(fSockfd, buffer, nbytes, flags)) < 0) {
            jack_error("Recv fd = %ld err = %s", fSockfd, strerror(errno));
        }
        return res;        
467
468
    }

Stephane Letz's avatar
Stephane Letz committed
469
    int JackNetUnixSocket::CatchHost(void* buffer, size_t nbytes, int flags)
470
    {
Stephane Letz's avatar
Stephane Letz committed
471
        socklen_t addr_len = sizeof(socket_address_t);
sletz's avatar
sletz committed
472
    #if defined(__sun__) || defined(sun)
Stephane Letz's avatar
Stephane Letz committed
473
        if (WaitRead() < 0) {
sletz's avatar
sletz committed
474
            return -1;
Stephane Letz's avatar
Stephane Letz committed
475
        }
sletz's avatar
sletz committed
476
    #endif
477
478
        int res;
        if ((res = recvfrom(fSockfd, buffer, nbytes, flags, reinterpret_cast<socket_address_t*>(&fSendAddr), &addr_len)) < 0) {
Stephane Letz's avatar
Stephane Letz committed
479
            jack_log("CatchHost fd = %ld err = %s", fSockfd, strerror(errno));
480
481
        }
        return res;                
482
483
484
485
    }

    net_error_t JackNetUnixSocket::GetError()
    {
Stephane Letz's avatar
Stephane Letz committed
486
        switch (errno) {
moret's avatar
moret committed
487
            case EAGAIN:
sletz's avatar
sletz committed
488
            case ETIMEDOUT:
moret's avatar
moret committed
489
                return NET_NO_DATA;
sletz's avatar
sletz committed
490

moret's avatar
moret committed
491
492
493
            case ECONNABORTED:
            case ECONNREFUSED:
            case ECONNRESET:
sletz's avatar
sletz committed
494
            case EINVAL:
moret's avatar
moret committed
495
496
            case EHOSTDOWN:
            case EHOSTUNREACH:
sletz's avatar
sletz committed
497
498
            case ENETDOWN:
            case ENETUNREACH:
moret's avatar
moret committed
499
                return NET_CONN_ERROR;
sletz's avatar
sletz committed
500

moret's avatar
moret committed
501
            default:
sletz's avatar
sletz committed
502
503
                //return NET_OP_ERROR;
                return NET_CONN_ERROR;
504
505
        }
    }
Stephane Letz's avatar
Stephane Letz committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
        
    void JackNetUnixSocket::PrintError()
    {
        switch (errno) {
                
            case EAGAIN:
                jack_error("JackNetUnixSocket : EAGAIN");
                break;
            case ETIMEDOUT:
                jack_error("JackNetUnixSocket : ETIMEDOUT");
                break;
            case ECONNABORTED:
                jack_error("JackNetUnixSocket : ECONNABORTED");
                break;
            case ECONNREFUSED:
                jack_error("JackNetUnixSocket : ECONNREFUSED");
                break;
            case ECONNRESET:
                jack_error("JackNetUnixSocket : ECONNRESET");
                break;
            case EINVAL:
                jack_error("JackNetUnixSocket : EINVAL");
                break;
            case EHOSTDOWN:
                jack_error("JackNetUnixSocket : EHOSTDOWN");
                break;
            case EHOSTUNREACH:
                jack_error("JackNetUnixSocket : EHOSTUNREACH");
                break;
            case ENETDOWN:
                jack_error("JackNetUnixSocket : ENETDOWN");
                break;
            case ENETUNREACH:
                jack_error("JackNetUnixSocket : ENETUNREACH");
                break;
            default:
                jack_error("JackNetUnixSocket : %d", errno);
                break;
        }
    }    
sletz's avatar
sletz committed
546
}