33 unsigned _bufferSize = CGestalt::max_buffer_frames();
42 if (WSAStartup(MAKEWORD(1,1),&localWSA)!= 0)
43 perror(
"Couldn't do WSAStartup");
46 thisSec = timeVals = timeSum = 0;
66 struct sockaddr_in serv_addr;
68 if((
_inSock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
69 perror(
"RemoteIO open_client: bad _inSock");
72 logMsg(
"Open RemoteIO server read socket on port %d = %d", port,
_inSock);
73 memset((
char *)&serv_addr, 0,
sizeof(serv_addr));
74 serv_addr.sin_family = AF_INET;
75 serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
76 serv_addr.sin_port = htons(port);
78 if(bind(
_inSock, (
struct sockaddr *) &serv_addr,
sizeof(
struct sockaddr)) < 0) {
79 perror(
"RemoteIO open_client: unable to bind");
90 perror(
"Close _inSock");
93 perror(
"Close _outSock");
100 socklen_t addrLen =
sizeof(
struct sockaddr_in);
104 perror(
"\tTCP_RemoteIO listen");
108 if ((
_outSock = accept(
_inSock, (
struct sockaddr *) & _clientAddr, & addrLen)) < 0) {
109 perror(
"\tTCP_RemoteIO accept");
112 logMsg(
"RemoteIO server accepted client socket connection");
120 #define THE_IO ((RemoteIO *) my_inst)
128 unsigned command, magic = RFS_PACKET_MAGIC;
129 int sock =
THE_IO->get_out_sock();
131 unsigned char * b_str = (
unsigned char *) _buffer;
132 CSL_RFS_MSG * pkt_header = (CSL_RFS_MSG *) b_str;
134 logMsg(
"Starting RemoteIO socket read loop (%d)", sock);
137 xfer_len = read(sock, (
char *) _buffer, RFS_PACKET_SIZE);
139 perror(
"RemoteIO loop read");
144 command = pkt_header->magic;
145 if ((command & 0xffffff00) != magic) {
149 command = command & 0x000000ff;
152 if (xfer_len != RFS_PACKET_SIZE) {
156 logMsg(
"RemoteIO set_client");
158 xfer_len = write(sock, (
char *) _buffer, RFS_PACKET_SIZE);
160 perror(
"RemoteIO set_client write");
163 THE_IO->process_request_packet();
182 unsigned packet_size = 0;
183 unsigned magic = RFS_PACKET_MAGIC;
184 unsigned char * sbuf = (
unsigned char *)
_buffer;
185 CSL_RFS_MSG * pkt_header = (CSL_RFS_MSG *) sbuf;
186 unsigned frames = pkt_header->frames;
189 if ((frames < 32) || (frames > CGestalt::max_buffer_frames())) {
193 if (pkt_header->channels !=
_outputs) {
199 packet_size = RFS_PACKET_SIZE + (frames *
_outputs *
sizeof(
sample));
200 memcpy(&sbuf[packet_size], &magic, 4);
204 bytes_wrote = write(
_outSock, (
char *) sbuf, packet_size);
209 memset(((
void *) & sbuf[RFS_PACKET_SIZE]), 0, (frames *
_outputs *
sizeof(
sample)));
212 for (
unsigned i = 0; i <
_outputs; i++)
214 + (i * frames *
sizeof(
sample))];
223 this->print_time_statistics(&now, &then, &thisSec, &timeSum, &timeVals);
void logMsg(const char *format,...)
These are the public logging messages.
#define CSL_DEFAULT_REQUEST_PORT
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
void process_request_packet()
void * RemoteIO_read_loop(void *inst)
float sample
(could be changed to int, or double)
int CSL_CreateThread(THREAD_START_ROUTINE pfnThreadProc, void *pvParam)
void init_io(unsigned in, unsigned out)
void allocateBuffers()
fcn to malloc storage buffers
#define CSL_CMD_NEXT_BUFFER
#define CSL_CMD_SET_CLIENT
status close()
open/close start/stop methods