1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program 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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // name: util_network.h
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
32 // originally 'randy_socket'
33 // author: Peng Bi (pbi@cs.princeton.edu)
34 // Ge Wang (gewang@cs.princeton.edu)
36 //-----------------------------------------------------------------------------
37 #ifndef __UTIL_NETWORK_H__
38 #define __UTIL_NETWORK_H__
40 #ifndef __PLATFORM_WIN32__
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <netinet/in.h>
48 #include "chuck_def.h"
51 #if defined(_cplusplus) || defined(__cplusplus)
56 typedef struct ck_socket_
* ck_socket
;
58 // create a UDP socket
59 ck_socket
ck_udp_create( );
60 // create a TCP socket
61 ck_socket
ck_tcp_create( int flags
);
62 // connect to a server
63 t_CKBOOL
ck_connect( ck_socket sock
, const char * hostname
, int port
);
64 // connect to a server
65 t_CKBOOL
ck_connect2( ck_socket sock
, const struct sockaddr
* serv_addr
,
68 t_CKBOOL
ck_bind( ck_socket sock
, int port
);
70 t_CKBOOL
ck_listen( ck_socket sock
, int backlog
);
72 ck_socket
ck_accept( ck_socket sock
);
75 int ck_send( ck_socket sock
, const char * buffer
, int len
);
76 // send using connect/sendto
77 int ck_send2( ck_socket sock
, const char * buffer
, int len
);
79 int ck_sendto( ck_socket sock
, const char * buffer
, int len
,
80 const struct sockaddr
* to
, int tolen
);
83 int ck_recv( ck_socket sock
, char * buffer
, int len
);
85 int ck_recv2( ck_socket sock
, char * buffer
, int len
);
87 int ck_recvfrom( ck_socket sock
, char * buffer
, int len
,
88 struct sockaddr
* from
, int * fromlen
);
91 int ck_send_timeout( ck_socket sock
, long sec
, long usec
);
93 int ck_recv_timeout( ck_socket sock
, long sec
, long usec
);
96 void ck_close( ck_socket sock
);
99 #if defined(_cplusplus) || defined(__cplusplus)