Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
port_forwarder.cpp File Reference
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string>
#include <vector>
#include <fcntl.h>
#include <unistd.h>
#include "inet.h"
#include "inet_file.h"
#include <pwd.h>

Go to the source code of this file.

Functions

bool scanChar (string s, char c, float &val)
 
bool ForwardBytes (int fd, int mysocket_write, char buf[65536])
 
int main (int argc, char **argv)
 

Variables

float fadein = 0
 
float fadeout = 0
 
float volume = 1
 
bool quit = false
 

Function Documentation

bool ForwardBytes ( int  fd,
int  mysocket_write,
char  buf[65536] 
)

Definition at line 38 of file port_forwarder.cpp.

References INET_BytesToRead(), INET_Recv(), and INET_Write().

Referenced by main().

39 {
40  if ( INET_BytesToRead( fd ) ) {
41  int ammt = INET_Recv( fd, buf, 65535 );
42  if (ammt == 0)
43  return false;
44  if (ammt == -1)
45  return true;
46  buf[ammt] = 0;
47  while ( -1 == INET_Write( mysocket_write, ammt, buf ) ) {}
48  }
49  return true;
50 }
int main ( int  argc,
char **  argv 
)

Definition at line 52 of file port_forwarder.cpp.

References ForwardBytes(), i, INET_AcceptFrom(), INET_cleanup(), INET_ConnectTo(), and INET_startup().

53 {
54  char buf[65536];
55  INET_startup();
56  int fd = -1;
57  int ofd = -1;
58  int outport = 6000;
59  char *outaddress = "192.168.1.6";
60  if (argc > 2)
61  outaddress = (char*) argv[2];
62  if (argc > 3)
63  outport = atoi( argv[3] );
64  ofd = INET_ConnectTo( outaddress, outport );
65  if (ofd != -1) {
66  for (int i = 0; i < 10 && fd == -1; i++) {
67  int port = 4364;
68  if (argc > 1) port = atoi( argv[1] );
69  fd = INET_AcceptFrom( port, "localhost" );
70  }
71  }
72  if (fd == -1)
73  return 1;
74  timeval t;
75  t.tv_sec = 5;
76  t.tv_usec = 0;
77  fd_set fdset;
78  FD_ZERO( &fdset );
79  FD_SET( fd, &fdset );
80  FD_SET( ofd, &fdset );
81  fcntl( fd, F_SETFL, O_NONBLOCK );
82  fcntl( ofd, F_SETFL, O_NONBLOCK );
83  while (1) {
84  //select(fd>ofd?(fd+1):(ofd+1),&fdset,NULL,NULL,&t);
85  if ( !ForwardBytes( fd, ofd, buf ) )
86  break;
87  if ( !ForwardBytes( ofd, fd, buf ) )
88  break;
89  }
90  INET_cleanup();
91  return 0;
92 }
bool scanChar ( string  s,
char  c,
float val 
)

Definition at line 20 of file port_forwarder.cpp.

References c.

Referenced by ScanOptions().

21 {
22  char cc[2] = {c, 0};
23  string::size_type loc;
24  bool anyvalid = false;
25  while ( ( loc = s.find( cc ) ) != string::npos ) {
26  bool valid = (loc == 0);
27  if (!valid && loc > 0)
28  valid = ( (s[loc-1] == '\n') || (s[loc-1] == '\r') );
29  s = s.substr( loc+1 );
30  if (valid) {
31  sscanf( s.c_str(), "%f", &val );
32  anyvalid = true;
33  }
34  }
35  return anyvalid;
36 }

Variable Documentation

float fadein = 0

Definition at line 17 of file port_forwarder.cpp.

Referenced by F0rkProcess(), main(), PlayMusic(), and ScanOptions().

float fadeout = 0

Definition at line 18 of file port_forwarder.cpp.

Referenced by F0rkProcess(), main(), PlayMusic(), and ScanOptions().

bool quit = false

Definition at line 37 of file port_forwarder.cpp.