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)
35 //-----------------------------------------------------------------------------
36 #ifndef __UTIL_NETWORK_H__
37 #define __UTIL_NETWORK_H__
39 #ifndef __PLATFORM_WIN32__
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
47 #include "chuck_def.h"
50 #if defined(_cplusplus) || defined(__cplusplus)
55 typedef struct ck_socket_
* ck_socket
;
57 // create a UDP socket
58 ck_socket
ck_udp_create( );
59 // create a TCP socket
60 ck_socket
ck_tcp_create( int flags
);
61 // connect to a server
62 t_CKBOOL
ck_connect( ck_socket sock
, const char * hostname
, int port
);
63 // connect to a server
64 t_CKBOOL
ck_connect2( ck_socket sock
, const struct sockaddr
* serv_addr
,
67 t_CKBOOL
ck_bind( ck_socket sock
, int port
);
69 t_CKBOOL
ck_listen( ck_socket sock
, int backlog
);
71 ck_socket
ck_accept( ck_socket sock
);
74 int ck_send( ck_socket sock
, const char * buffer
, int len
);
75 // send using connect/sendto
76 int ck_send2( ck_socket sock
, const char * buffer
, int len
);
78 int ck_sendto( ck_socket sock
, const char * buffer
, int len
,
79 const struct sockaddr
* to
, int tolen
);
82 int ck_recv( ck_socket sock
, char * buffer
, int len
);
84 int ck_recvfrom( ck_socket sock
, char * buffer
, int len
,
85 struct sockaddr
* from
, int * fromlen
);
88 int ck_send_timeout( ck_socket sock
, long sec
, long usec
);
90 int ck_recv_timeout( ck_socket sock
, long sec
, long usec
);
93 void ck_close( ck_socket sock
);
96 #if defined(_cplusplus) || defined(__cplusplus)