*** empty log message ***
[chuck-blob.git] / v2 / util_network.h
blobe654eb5ddf2da5d81f1da88018c062c8bf4029b9
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
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // name: util_network.h
27 // desc: sockets
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 // date: Winter 2003
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>
44 #else
45 #include <windows.h>
46 #endif
48 #include "chuck_def.h"
51 #if defined(_cplusplus) || defined(__cplusplus)
52 extern "C" {
53 #endif
55 // our socket type
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,
66 int addrlen);
67 // bind to a port
68 t_CKBOOL ck_bind( ck_socket sock, int port );
69 // listen (TCP)
70 t_CKBOOL ck_listen( ck_socket sock, int backlog );
71 // accept (TCP)
72 ck_socket ck_accept( ck_socket sock );
74 // send
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 );
78 // send a datagram
79 int ck_sendto( ck_socket sock, const char * buffer, int len,
80 const struct sockaddr * to, int tolen );
82 // recv
83 int ck_recv( ck_socket sock, char * buffer, int len );
84 // recv
85 int ck_recv2( ck_socket sock, char * buffer, int len );
86 // recv a datagram
87 int ck_recvfrom( ck_socket sock, char * buffer, int len,
88 struct sockaddr * from, int * fromlen );
90 // send timeout
91 int ck_send_timeout( ck_socket sock, long sec, long usec );
92 // recv timeout
93 int ck_recv_timeout( ck_socket sock, long sec, long usec );
95 // close the socket
96 void ck_close( ck_socket sock );
99 #if defined(_cplusplus) || defined(__cplusplus)
101 #endif
106 #endif