*** empty log message ***
[chuck-blob.git] / v1 / util_network.h
blob01b61ac593c59fc9d5ceba2fde92705ae5833b36
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 //-----------------------------------------------------------------------------
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>
43 #else
44 #include <windows.h>
45 #endif
47 #include "chuck_def.h"
50 #if defined(_cplusplus) || defined(__cplusplus)
51 extern "C" {
52 #endif
54 // our socket type
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,
65 int addrlen);
66 // bind to a port
67 t_CKBOOL ck_bind( ck_socket sock, int port );
68 // listen (TCP)
69 t_CKBOOL ck_listen( ck_socket sock, int backlog );
70 // accept (TCP)
71 ck_socket ck_accept( ck_socket sock );
73 // send
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 );
77 // send a datagram
78 int ck_sendto( ck_socket sock, const char * buffer, int len,
79 const struct sockaddr * to, int tolen );
81 // recv
82 int ck_recv( ck_socket sock, char * buffer, int len );
83 // recv a datagram
84 int ck_recvfrom( ck_socket sock, char * buffer, int len,
85 struct sockaddr * from, int * fromlen );
87 // send timeout
88 int ck_send_timeout( ck_socket sock, long sec, long usec );
89 // recv timeout
90 int ck_recv_timeout( ck_socket sock, long sec, long usec );
92 // close the socket
93 void ck_close( ck_socket sock );
96 #if defined(_cplusplus) || defined(__cplusplus)
98 #endif
103 #endif