From 9c9f0832d8ee361c6aedde3d105494b04a3ecbb1 Mon Sep 17 00:00:00 2001 From: moret Date: Tue, 5 Aug 2008 16:05:03 +0000 Subject: [PATCH] Correct NetInterface git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2776 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackNetDriver.cpp | 76 ++++++------- common/JackNetInterface.cpp | 193 +++++++++++++++++++-------------- common/JackNetInterface.h | 180 +++++++++++++++--------------- common/JackNetManager.cpp | 62 +++++------ common/JackNetManager.h | 14 +-- common/JackNetTool.cpp | 4 +- common/JackNetUnixSocket.cpp | 36 +++--- common/JackNetUnixSocket.h | 118 ++++++++++---------- common/JackPlatformNetSocket.h | 4 +- windows/JackNetWinSocket.cpp | 156 +++++++++++++------------- windows/JackNetWinSocket.h | 114 +++++++++---------- 11 files changed, 490 insertions(+), 467 deletions(-) diff --git a/common/JackNetDriver.cpp b/common/JackNetDriver.cpp index e3dab7ee..88e46cc8 100644 --- a/common/JackNetDriver.cpp +++ b/common/JackNetDriver.cpp @@ -112,9 +112,9 @@ namespace Jack fParams.fReturnAudioChannels = fPlaybackChannels; fParams.fSlaveSyncMode = fEngineControl->fSyncMode; - //display some additional infos - jack_info ( "NetAdapter started in %s mode %s Master's transport sync.", - ( fParams.fSlaveSyncMode ) ? "sync" : "async", ( fParams.fTransportSync ) ? "with" : "without" ); + //display some additional infos + jack_info ( "NetAdapter started in %s mode %s Master's transport sync.", + ( fParams.fSlaveSyncMode ) ? "sync" : "async", ( fParams.fTransportSync ) ? "with" : "without" ); if ( !JackNetSlaveInterface::Init() ) return false;; @@ -130,7 +130,7 @@ namespace Jack fMidiCapturePortList = new jack_port_id_t [fParams.fSendMidiChannels]; fMidiPlaybackPortList = new jack_port_id_t [fParams.fReturnMidiChannels]; - //register jack ports + //register jack ports if ( AllocPorts() != 0 ) { jack_error ( "Can't allocate ports." ); @@ -341,12 +341,12 @@ namespace Jack int JackNetDriver::Read() { uint midi_port_index; - int audio_port_index; + uint audio_port_index; //buffers for ( midi_port_index = 0; midi_port_index < fParams.fSendMidiChannels; midi_port_index++ ) fNetMidiCaptureBuffer->SetBuffer ( midi_port_index, GetMidiInputBuffer ( midi_port_index ) ); - for ( audio_port_index = 0; audio_port_index < fCaptureChannels; audio_port_index++ ) + for ( audio_port_index = 0; audio_port_index < fParams.fSendAudioChannels; audio_port_index++ ) fNetAudioCaptureBuffer->SetBuffer ( audio_port_index, GetInputBuffer ( audio_port_index ) ); #ifdef JACK_MONITOR @@ -396,7 +396,7 @@ namespace Jack memset ( fTxData, 0, fPayloadSize ); SetSyncPacket(); - //send sync + //send sync if ( SyncSend() == SOCKET_ERROR ) return SOCKET_ERROR; @@ -404,7 +404,7 @@ namespace Jack fNetTimeMon->Add ( ( ( float ) ( GetMicroSeconds() - JackDriver::fBeginDateUst ) / ( float ) fEngineControl->fPeriodUsecs ) * 100.f ); #endif - //send data + //send data if ( DataSend() == SOCKET_ERROR ) return SOCKET_ERROR; @@ -540,36 +540,36 @@ namespace Jack param = ( const jack_driver_param_t* ) node->data; switch ( param->character ) { - case 'a' : - multicast_ip = strdup ( param->value.str ); - break; - case 'p': - udp_port = param->value.ui; - break; - case 'M': - mtu = param->value.i; - break; - case 'C': - audio_capture_ports = param->value.i; - break; - case 'P': - audio_playback_ports = param->value.i; - break; - case 'i': - midi_input_ports = param->value.i; - break; - case 'o': - midi_output_ports = param->value.i; - break; - case 'n' : - strncpy ( name, param->value.str, JACK_CLIENT_NAME_SIZE ); - break; - case 't' : - transport_sync = param->value.ui; - break; - case 'f' : - network_mode = 'f'; - break; + case 'a' : + multicast_ip = strdup ( param->value.str ); + break; + case 'p': + udp_port = param->value.ui; + break; + case 'M': + mtu = param->value.i; + break; + case 'C': + audio_capture_ports = param->value.i; + break; + case 'P': + audio_playback_ports = param->value.i; + break; + case 'i': + midi_input_ports = param->value.i; + break; + case 'o': + midi_output_ports = param->value.i; + break; + case 'n' : + strncpy ( name, param->value.str, JACK_CLIENT_NAME_SIZE ); + break; + case 't' : + transport_sync = param->value.ui; + break; + case 'f' : + network_mode = 'f'; + break; } } diff --git a/common/JackNetInterface.cpp b/common/JackNetInterface.cpp index d395bb7e..c1a12a8a 100644 --- a/common/JackNetInterface.cpp +++ b/common/JackNetInterface.cpp @@ -32,7 +32,7 @@ namespace Jack JackNetInterface::JackNetInterface ( const char* ip, int port ) : fSocket ( ip, port ) { - jack_log ( "JackNetInterface::JackNetInterface ip = %s port = %d", ip, port ); + jack_log ( "JackNetInterface::JackNetInterface ip = %s port = %d", ip, port ); fMulticastIP = new char[strlen ( ip ) + 1]; strcpy ( fMulticastIP, ip ); @@ -40,17 +40,16 @@ namespace Jack JackNetInterface::JackNetInterface ( session_params_t& params, JackNetSocket& socket ) : fSocket ( socket ) { - jack_log ( "JackNetInterface::JackNetInterface ID = %d", params.fID ); + jack_log ( "JackNetInterface::JackNetInterface ID = %d", params.fID ); fParams = params; - SetParams(); fMulticastIP = new char[strlen ( fSocket.GetSendIP() ) + 1]; strcpy ( fMulticastIP, fSocket.GetSendIP() ); } JackNetInterface::~JackNetInterface() { - jack_log ( "JackNetInterface::~JackNetInterface" ); + jack_log ( "JackNetInterface::~JackNetInterface" ); fSocket.Close(); SocketAPIEnd(); delete[] fTxBuffer; @@ -64,8 +63,6 @@ namespace Jack void JackNetInterface::SetParams() { - jack_log ( "JackNetInterface::SetParams" ); - fNSubProcess = fParams.fPeriodSize / fParams.fFramesPerPacket; //TX header init @@ -92,18 +89,6 @@ namespace Jack fTxData = fTxBuffer + sizeof ( packet_header_t ); fRxData = fRxBuffer + sizeof ( packet_header_t ); - //midi net buffers - fNetMidiCaptureBuffer = new NetMidiBuffer ( &fParams, fParams.fSendMidiChannels, fRxData ); - fNetMidiPlaybackBuffer = new NetMidiBuffer ( &fParams, fParams.fReturnMidiChannels, fTxData ); - - //audio net buffers - fNetAudioCaptureBuffer = new NetAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData ); - fNetAudioPlaybackBuffer = new NetAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData ); - - //audio netbuffer length - fAudioTxLen = sizeof ( packet_header_t ) + fNetAudioPlaybackBuffer->GetSize(); - fAudioRxLen = sizeof ( packet_header_t ) + fNetAudioCaptureBuffer->GetSize(); - //payload size fPayloadSize = fParams.fMtu - sizeof ( packet_header_t ); } @@ -112,7 +97,7 @@ namespace Jack bool JackNetSlaveInterface::Init() { - jack_log ( "JackNetSlaveInterface::NetInit()" ); + jack_log ( "JackNetSlaveInterface::Init()" ); //set the parameters to send strcpy ( fParams.fPacketType, "params" ); @@ -214,6 +199,28 @@ namespace Jack return NET_ROLLING; } + void JackNetSlaveInterface::SetParams() + { + jack_log ( "JackNetSlaveInterface::SetParams" ); + + JackNetInterface::SetParams(); + + fTxHeader.fDataStream = 'r'; + fRxHeader.fDataStream = 's'; + + //midi net buffers + fNetMidiCaptureBuffer = new NetMidiBuffer ( &fParams, fParams.fSendMidiChannels, fRxData ); + fNetMidiPlaybackBuffer = new NetMidiBuffer ( &fParams, fParams.fReturnMidiChannels, fTxData ); + + //audio net buffers + fNetAudioCaptureBuffer = new NetAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData ); + fNetAudioPlaybackBuffer = new NetAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData ); + + //audio netbuffer length + fAudioTxLen = sizeof ( packet_header_t ) + fNetAudioPlaybackBuffer->GetSize(); + fAudioRxLen = sizeof ( packet_header_t ) + fNetAudioCaptureBuffer->GetSize(); + } + int JackNetSlaveInterface::Recv ( size_t size, int flags ) { int rx_bytes = fSocket.Recv ( fRxBuffer, size, flags ); @@ -291,27 +298,27 @@ namespace Jack { switch ( rx_head->fDataType ) { - case 'm': //midi - rx_bytes = Recv ( rx_head->fPacketSize, 0 ); - fRxHeader.fCycle = rx_head->fCycle; - fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; - fNetMidiCaptureBuffer->RenderFromNetwork ( rx_head->fSubCycle, rx_bytes - sizeof ( packet_header_t ) ); - if ( ++recvd_midi_pckt == rx_head->fNMidiPckt ) - fNetMidiCaptureBuffer->RenderToJackPorts(); - break; - case 'a': //audio - rx_bytes = Recv ( rx_head->fPacketSize, 0 ); - if ( !IsNextPacket ( &fRxHeader, rx_head, fNSubProcess ) ) - jack_error ( "Packet(s) missing..." ); - fRxHeader.fCycle = rx_head->fCycle; - fRxHeader.fSubCycle = rx_head->fSubCycle; - fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; - fNetAudioCaptureBuffer->RenderToJackPorts ( rx_head->fSubCycle ); - break; - case 's': //sync - jack_info ( "NetSlave : overloaded, skipping receive." ); - fRxHeader.fCycle = rx_head->fCycle; - return 0; + case 'm': //midi + rx_bytes = Recv ( rx_head->fPacketSize, 0 ); + fRxHeader.fCycle = rx_head->fCycle; + fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; + fNetMidiCaptureBuffer->RenderFromNetwork ( rx_head->fSubCycle, rx_bytes - sizeof ( packet_header_t ) ); + if ( ++recvd_midi_pckt == rx_head->fNMidiPckt ) + fNetMidiCaptureBuffer->RenderToJackPorts(); + break; + case 'a': //audio + rx_bytes = Recv ( rx_head->fPacketSize, 0 ); + if ( !IsNextPacket ( &fRxHeader, rx_head, fNSubProcess ) ) + jack_error ( "Packet(s) missing..." ); + fRxHeader.fCycle = rx_head->fCycle; + fRxHeader.fSubCycle = rx_head->fSubCycle; + fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; + fNetAudioCaptureBuffer->RenderToJackPorts ( rx_head->fSubCycle ); + break; + case 's': //sync + jack_info ( "NetSlave : overloaded, skipping receive." ); + fRxHeader.fCycle = rx_head->fCycle; + return 0; } } } @@ -448,6 +455,28 @@ namespace Jack return true; } + void JackNetMasterInterface::SetParams() + { + jack_log ( "JackNetMasterInterface::SetParams" ); + + JackNetInterface::SetParams(); + + fTxHeader.fDataStream = 's'; + fRxHeader.fDataStream = 'r'; + + //midi net buffers + fNetMidiCaptureBuffer = new NetMidiBuffer ( &fParams, fParams.fSendMidiChannels, fTxData ); + fNetMidiPlaybackBuffer = new NetMidiBuffer ( &fParams, fParams.fReturnMidiChannels, fRxData ); + + //audio net buffers + fNetAudioCaptureBuffer = new NetAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData ); + fNetAudioPlaybackBuffer = new NetAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData ); + + //audio netbuffer length + fAudioTxLen = sizeof ( packet_header_t ) + fNetAudioPlaybackBuffer->GetSize(); + fAudioRxLen = sizeof ( packet_header_t ) + fNetAudioCaptureBuffer->GetSize(); + } + void JackNetMasterInterface::Exit() { jack_log ( "JackNetMaster::Exit, ID %u", fParams.fID ); @@ -538,7 +567,7 @@ namespace Jack memcpy ( fTxBuffer, &fTxHeader, sizeof ( packet_header_t ) ); //and send if ( Send ( fTxHeader.fPacketSize, 0 ) == SOCKET_ERROR ) - return SOCKET_ERROR; + return SOCKET_ERROR; } } @@ -558,7 +587,7 @@ namespace Jack fNetAudioCaptureBuffer->RenderFromJackPorts ( subproc ); //and send if ( Send ( fTxHeader.fPacketSize, 0 ) == SOCKET_ERROR ) - return SOCKET_ERROR; + return SOCKET_ERROR; } } @@ -579,25 +608,25 @@ namespace Jack switch ( fParams.fNetworkMode ) { - case 'n' : - //normal use of the network : allow to use full bandwith - // - extra latency is set to one cycle, what is the time needed to receive streams using full network bandwith - // - if the network is too fast, just wait the next cycle, the benefit here is the master's cycle is shorter - // - indeed, data is supposed to be on the network rx buffer, so we don't have to wait for it - if ( cycle_offset == 0 ) - return 0; - else + case 'n' : + //normal use of the network : allow to use full bandwith + // - extra latency is set to one cycle, what is the time needed to receive streams using full network bandwith + // - if the network is too fast, just wait the next cycle, the benefit here is the master's cycle is shorter + // - indeed, data is supposed to be on the network rx buffer, so we don't have to wait for it + if ( cycle_offset == 0 ) + return 0; + else + rx_bytes = Recv ( rx_head->fPacketSize, 0 ); + break; + case 'f' : + //fast mode suppose the network bandwith is larger than required for the transmission (only a few channels for example) + // - packets can be quickly received, quickly is here relative to the cycle duration + // - here, receive data, we can't keep it queued on the rx buffer, + // - but if there is a cycle offset, tell the user, that means we're not in fast mode anymore, network is too slow rx_bytes = Recv ( rx_head->fPacketSize, 0 ); - break; - case 'f' : - //fast mode suppose the network bandwith is larger than required for the transmission (only a few channels for example) - // - packets can be quickly received, quickly is here relative to the cycle duration - // - here, receive data, we can't keep it queued on the rx buffer, - // - but if there is a cycle offset, tell the user, that means we're not in fast mode anymore, network is too slow - rx_bytes = Recv ( rx_head->fPacketSize, 0 ); - if ( cycle_offset ) - jack_error ( "'%s' can't run in fast network mode, data received too late (%d cycle(s) offset)", fParams.fName, cycle_offset ); - break; + if ( cycle_offset ) + jack_error ( "'%s' can't run in fast network mode, data received too late (%d cycle(s) offset)", fParams.fName, cycle_offset ); + break; } return rx_bytes; @@ -630,28 +659,28 @@ namespace Jack //read data switch ( rx_head->fDataType ) { - case 'm': //midi - Recv ( rx_head->fPacketSize, 0 ); - fRxHeader.fCycle = rx_head->fCycle; - fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; - fNetMidiPlaybackBuffer->RenderFromNetwork ( rx_head->fSubCycle, rx_bytes - sizeof ( packet_header_t ) ); - if ( ++midi_recvd_pckt == rx_head->fNMidiPckt ) - fNetMidiPlaybackBuffer->RenderToJackPorts(); - jumpcnt = 0; - break; - case 'a': //audio - Recv ( rx_head->fPacketSize, 0 ); - if ( !IsNextPacket ( &fRxHeader, rx_head, fNSubProcess ) ) - jack_error ( "Packet(s) missing from '%s'...", fParams.fName ); - fRxHeader.fCycle = rx_head->fCycle; - fRxHeader.fSubCycle = rx_head->fSubCycle; - fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; - fNetAudioPlaybackBuffer->RenderToJackPorts ( rx_head->fSubCycle ); - jumpcnt = 0; - break; - case 's': //sync - if ( rx_head->fCycle == fTxHeader.fCycle ) - return 0; + case 'm': //midi + Recv ( rx_head->fPacketSize, 0 ); + fRxHeader.fCycle = rx_head->fCycle; + fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; + fNetMidiPlaybackBuffer->RenderFromNetwork ( rx_head->fSubCycle, rx_bytes - sizeof ( packet_header_t ) ); + if ( ++midi_recvd_pckt == rx_head->fNMidiPckt ) + fNetMidiPlaybackBuffer->RenderToJackPorts(); + jumpcnt = 0; + break; + case 'a': //audio + Recv ( rx_head->fPacketSize, 0 ); + if ( !IsNextPacket ( &fRxHeader, rx_head, fNSubProcess ) ) + jack_error ( "Packet(s) missing from '%s'...", fParams.fName ); + fRxHeader.fCycle = rx_head->fCycle; + fRxHeader.fSubCycle = rx_head->fSubCycle; + fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; + fNetAudioPlaybackBuffer->RenderToJackPorts ( rx_head->fSubCycle ); + jumpcnt = 0; + break; + case 's': //sync + if ( rx_head->fCycle == fTxHeader.fCycle ) + return 0; } } } diff --git a/common/JackNetInterface.h b/common/JackNetInterface.h index 67b969ec..bbad6acc 100644 --- a/common/JackNetInterface.h +++ b/common/JackNetInterface.h @@ -31,53 +31,53 @@ namespace Jack class EXPORT JackNetInterface { - protected: - session_params_t fParams; - JackNetSocket fSocket; - char* fMulticastIP; - uint fNSubProcess; - - //headers - packet_header_t fTxHeader; - packet_header_t fRxHeader; - - //network buffers - char* fTxBuffer; - char* fRxBuffer; - char* fTxData; - char* fRxData; - - //jack buffers - NetMidiBuffer* fNetMidiCaptureBuffer; - NetMidiBuffer* fNetMidiPlaybackBuffer; - NetAudioBuffer* fNetAudioCaptureBuffer; - NetAudioBuffer* fNetAudioPlaybackBuffer; - - //sizes - int fAudioRxLen; - int fAudioTxLen; - int fPayloadSize; - - void SetParams(); - - //virtual methods : depends on the sub class master/slave - virtual bool Init() = 0; - - virtual int SyncRecv() = 0; - virtual int SyncSend() = 0; - virtual int DataRecv() = 0; - virtual int DataSend() = 0; - - virtual int Send ( size_t size, int flags ) = 0; - virtual int Recv ( size_t size, int flags ) = 0; - - JackNetInterface() - {} - JackNetInterface ( const char* ip, int port ); - JackNetInterface ( session_params_t& params, JackNetSocket& socket ); - - public: - ~JackNetInterface(); + protected: + session_params_t fParams; + JackNetSocket fSocket; + char* fMulticastIP; + uint fNSubProcess; + + //headers + packet_header_t fTxHeader; + packet_header_t fRxHeader; + + //network buffers + char* fTxBuffer; + char* fRxBuffer; + char* fTxData; + char* fRxData; + + //jack buffers + NetMidiBuffer* fNetMidiCaptureBuffer; + NetMidiBuffer* fNetMidiPlaybackBuffer; + NetAudioBuffer* fNetAudioCaptureBuffer; + NetAudioBuffer* fNetAudioPlaybackBuffer; + + //sizes + int fAudioRxLen; + int fAudioTxLen; + int fPayloadSize; + + virtual void SetParams(); + + //virtual methods : depends on the sub class master/slave + virtual bool Init() = 0; + + virtual int SyncRecv() = 0; + virtual int SyncSend() = 0; + virtual int DataRecv() = 0; + virtual int DataSend() = 0; + + virtual int Send ( size_t size, int flags ) = 0; + virtual int Recv ( size_t size, int flags ) = 0; + + JackNetInterface() + {} + JackNetInterface ( const char* ip, int port ); + JackNetInterface ( session_params_t& params, JackNetSocket& socket ); + + public: + virtual ~JackNetInterface(); }; /** @@ -86,28 +86,26 @@ namespace Jack class EXPORT JackNetSlaveInterface : public JackNetInterface { - protected: - bool Init(); - net_status_t GetNetMaster(); - net_status_t SendMasterStartSync(); - int SyncRecv(); - int SyncSend(); - int DataRecv(); - int DataSend(); - - int Recv ( size_t size, int flags ); - int Send ( size_t size, int flags ); - - public: - JackNetSlaveInterface() - {} - JackNetSlaveInterface ( const char* ip, int port ) : JackNetInterface ( ip, port ) - { - fTxHeader.fDataStream = 'r'; - fRxHeader.fDataStream = 's'; - } - ~JackNetSlaveInterface() - {} + protected: + bool Init(); + net_status_t GetNetMaster(); + net_status_t SendMasterStartSync(); + void SetParams(); + int SyncRecv(); + int SyncSend(); + int DataRecv(); + int DataSend(); + + int Recv ( size_t size, int flags ); + int Send ( size_t size, int flags ); + + public: + JackNetSlaveInterface() + {} + JackNetSlaveInterface ( const char* ip, int port ) : JackNetInterface ( ip, port ) + {} + ~JackNetSlaveInterface() + {} }; /** @@ -116,29 +114,27 @@ namespace Jack class EXPORT JackNetMasterInterface : public JackNetInterface { - protected: - bool fRunning; - - bool Init(); - void Exit(); - int SyncRecv(); - int SyncSend(); - int DataRecv(); - int DataSend(); - - int Send ( size_t size, int flags ); - int Recv ( size_t size, int flags ); - - public: - JackNetMasterInterface() : fRunning ( false ) - {} - JackNetMasterInterface ( session_params_t& params, JackNetSocket& socket ) : JackNetInterface ( params, socket ) - { - fTxHeader.fDataStream = 's'; - fRxHeader.fDataStream = 'r'; - } - ~JackNetMasterInterface() - {} + protected: + bool fRunning; + + bool Init(); + void SetParams(); + void Exit(); + int SyncRecv(); + int SyncSend(); + int DataRecv(); + int DataSend(); + + int Send ( size_t size, int flags ); + int Recv ( size_t size, int flags ); + + public: + JackNetMasterInterface() : fRunning ( false ) + {} + JackNetMasterInterface ( session_params_t& params, JackNetSocket& socket ) : JackNetInterface ( params, socket ) + {} + ~JackNetMasterInterface() + {} }; } diff --git a/common/JackNetManager.cpp b/common/JackNetManager.cpp index 855f58e3..bbab0261 100644 --- a/common/JackNetManager.cpp +++ b/common/JackNetManager.cpp @@ -57,6 +57,8 @@ namespace Jack for ( port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ ) fMidiPlaybackPorts[port_index] = NULL; + SetParams(); + //monitor #ifdef JACK_MONITOR fPeriodUsecs = ( int ) ( 1000000.f * ( ( float ) fParams.fPeriodSize / ( float ) fParams.fSampleRate ) ); @@ -123,7 +125,7 @@ namespace Jack goto fail; } - //process can now run + //process can now run fRunning = true; //finally activate jack client @@ -137,7 +139,7 @@ namespace Jack return true; -fail: + fail: FreePorts(); jack_client_close ( fJackClient ); fJackClient = NULL; @@ -146,7 +148,7 @@ fail: int JackNetMaster::AllocPorts() { - jack_log ( "JackNetMaster::AllocPorts" ); + jack_log ( "JackNetMaster::AllocPorts" ); uint i; char name[24]; @@ -240,21 +242,17 @@ fail: //buffers for ( port_index = 0; port_index < fParams.fSendMidiChannels; port_index++ ) - fNetMidiCaptureBuffer->SetBuffer ( port_index, - static_cast ( jack_port_get_buffer ( fMidiCapturePorts[port_index], - fParams.fPeriodSize ) ) ); + fNetMidiCaptureBuffer->SetBuffer ( port_index, static_cast ( jack_port_get_buffer ( fMidiCapturePorts[port_index], + fParams.fPeriodSize ) ) ); for ( port_index = 0; port_index < fParams.fSendAudioChannels; port_index++ ) - fNetAudioCaptureBuffer->SetBuffer ( port_index, - static_cast ( jack_port_get_buffer ( fAudioCapturePorts[port_index], - fParams.fPeriodSize ) ) ); + fNetAudioCaptureBuffer->SetBuffer ( port_index, static_cast ( jack_port_get_buffer ( fAudioCapturePorts[port_index], + fParams.fPeriodSize ) ) ); for ( port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++ ) - fNetMidiPlaybackBuffer->SetBuffer ( port_index, - static_cast ( jack_port_get_buffer ( fMidiPlaybackPorts[port_index], - fParams.fPeriodSize ) ) ); + fNetMidiPlaybackBuffer->SetBuffer ( port_index, static_cast ( jack_port_get_buffer ( fMidiPlaybackPorts[port_index], + fParams.fPeriodSize ) ) ); for ( port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++ ) - fNetAudioPlaybackBuffer->SetBuffer ( port_index, - static_cast ( jack_port_get_buffer ( fAudioPlaybackPorts[port_index], - fParams.fPeriodSize ) ) ); + fNetAudioPlaybackBuffer->SetBuffer ( port_index, static_cast ( jack_port_get_buffer ( fAudioPlaybackPorts[port_index], + fParams.fPeriodSize ) ) ); //Set the first packet to send memset ( fTxData, 0, fPayloadSize ); @@ -315,11 +313,11 @@ fail: param = ( const jack_driver_param_t* ) node->data; switch ( param->character ) { - case 'a' : - fMulticastIP = strdup ( param->value.str ); - break; - case 'p': - fSocket.SetPort ( param->value.ui ); + case 'a' : + fMulticastIP = strdup ( param->value.str ); + break; + case 'p': + fSocket.SetPort ( param->value.ui ); } } @@ -440,19 +438,19 @@ fail: { switch ( GetPacketType ( ¶ms ) ) { - case SLAVE_AVAILABLE: - if ( ( net_master = MasterInit ( params ) ) ) - SessionParamsDisplay ( &net_master->fParams ); - else - jack_error ( "Can't init new net master..." ); - jack_info ( "Waiting for a slave..." ); - break; - case KILL_MASTER: - if ( KillMaster ( ¶ms ) ) + case SLAVE_AVAILABLE: + if ( ( net_master = MasterInit ( params ) ) ) + SessionParamsDisplay ( &net_master->fParams ); + else + jack_error ( "Can't init new net master..." ); jack_info ( "Waiting for a slave..." ); - break; - default: - break; + break; + case KILL_MASTER: + if ( KillMaster ( ¶ms ) ) + jack_info ( "Waiting for a slave..." ); + break; + default: + break; } } } diff --git a/common/JackNetManager.h b/common/JackNetManager.h index cf4a5c57..8bee0a41 100644 --- a/common/JackNetManager.h +++ b/common/JackNetManager.h @@ -30,13 +30,13 @@ namespace Jack { class JackNetMasterManager; - /** - \Brief This class describes a Net Master - */ + /** + \Brief This class describes a Net Master + */ class JackNetMaster : public JackNetMasterInterface { - friend class JackNetMasterManager; + friend class JackNetMasterManager; private: static int SetProcess ( jack_nframes_t nframes, void* arg ); @@ -76,9 +76,9 @@ namespace Jack typedef std::list master_list_t; typedef master_list_t::iterator master_list_it_t; - /** - \Brief This class describer the Network Manager - */ + /** + \Brief This class describer the Network Manager + */ class JackNetMasterManager { diff --git a/common/JackNetTool.cpp b/common/JackNetTool.cpp index 8ae0bdfa..901edbf6 100644 --- a/common/JackNetTool.cpp +++ b/common/JackNetTool.cpp @@ -342,7 +342,7 @@ namespace Jack if ( !params->fSendAudioChannels && !params->fReturnAudioChannels ) return ( params->fFramesPerPacket = params->fPeriodSize ); jack_nframes_t period = ( int ) powf ( 2.f, ( int ) ( log ( ( params->fMtu - sizeof ( packet_header_t ) ) - / ( max ( params->fReturnAudioChannels, params->fSendAudioChannels ) * sizeof ( sample_t ) ) ) / log ( 2 ) ) ); + / ( max ( params->fReturnAudioChannels, params->fSendAudioChannels ) * sizeof ( sample_t ) ) ) / log ( 2 ) ) ); ( period > params->fPeriodSize ) ? params->fFramesPerPacket = params->fPeriodSize : params->fFramesPerPacket = period; return params->fFramesPerPacket; } @@ -353,7 +353,7 @@ namespace Jack float audio_size = params->fMtu * ( params->fPeriodSize / params->fFramesPerPacket ); //midi float midi_size = params->fMtu * ( max ( params->fSendMidiChannels, params->fReturnMidiChannels ) * - params->fPeriodSize * sizeof ( sample_t ) / ( params->fMtu - sizeof ( packet_header_t ) ) ); + params->fPeriodSize * sizeof ( sample_t ) / ( params->fMtu - sizeof ( packet_header_t ) ) ); //return : sizes of sync + audio + midi return ( params->fMtu + ( int ) audio_size + ( int ) midi_size ); } diff --git a/common/JackNetUnixSocket.cpp b/common/JackNetUnixSocket.cpp index 6ab78cf6..f1f7d709 100644 --- a/common/JackNetUnixSocket.cpp +++ b/common/JackNetUnixSocket.cpp @@ -24,7 +24,7 @@ namespace Jack //utility ********************************************************************************************************* int GetHostName ( char * name, int size ) { - if ( gethostname ( name, size) == SOCKET_ERROR ) + if ( gethostname ( name, size ) == SOCKET_ERROR ) { jack_error ( "Can't get 'hostname' : %s", strerror ( NET_ERROR_CODE ) ); strcpy ( name, "default" ); @@ -234,7 +234,7 @@ namespace Jack //more than 1sec else { - float sec = static_cast( us ) / 1000000.f; + float sec = static_cast ( us ) / 1000000.f; timeout.tv_sec = ( int ) sec; float usec = ( sec - static_cast ( timeout.tv_sec ) ) * 1000000; timeout.tv_usec = ( int ) usec; @@ -289,22 +289,22 @@ namespace Jack { switch ( errno ) { - case EAGAIN: - return NET_NO_DATA; - case ECONNABORTED: - return NET_CONN_ERROR; - case EINVAL: - return NET_CONN_ERROR; - case ECONNREFUSED: - return NET_CONN_ERROR; - case ECONNRESET: - return NET_CONN_ERROR; - case EHOSTDOWN: - return NET_CONN_ERROR; - case EHOSTUNREACH: - return NET_CONN_ERROR; - default: - return NET_OP_ERROR; + case EAGAIN: + return NET_NO_DATA; + case ECONNABORTED: + return NET_CONN_ERROR; + case EINVAL: + return NET_CONN_ERROR; + case ECONNREFUSED: + return NET_CONN_ERROR; + case ECONNRESET: + return NET_CONN_ERROR; + case EHOSTDOWN: + return NET_CONN_ERROR; + case EHOSTUNREACH: + return NET_CONN_ERROR; + default: + return NET_OP_ERROR; } } } diff --git a/common/JackNetUnixSocket.h b/common/JackNetUnixSocket.h index f7e70466..7f4a0d62 100644 --- a/common/JackNetUnixSocket.h +++ b/common/JackNetUnixSocket.h @@ -39,65 +39,65 @@ namespace Jack //JackNetUnixSocket******************************************** class EXPORT JackNetUnixSocket { - private: - int fSockfd; - int fPort; - - struct sockaddr_in fSendAddr; - struct sockaddr_in fRecvAddr; - public: - JackNetUnixSocket(); - JackNetUnixSocket ( const char* ip, int port ); - JackNetUnixSocket ( const JackNetUnixSocket& ); - ~JackNetUnixSocket(); - - JackNetUnixSocket& operator= ( const JackNetUnixSocket& socket ); - - //socket management - int NewSocket(); - int Bind(); - int BindWith ( const char* ip ); - int BindWith ( int port ); - int Connect(); - int ConnectTo ( const char* ip ); - void Close(); - void Reset(); - bool IsSocket(); - - //IP/PORT management - void SetPort ( int port ); - int GetPort(); - - //address management - int SetAddress ( const char* ip, int port ); - char* GetSendIP(); - char* GetRecvIP(); - - //utility - int GetName ( char* name ); - int JoinMCastGroup ( const char* mcast_ip ); - void CopyParams ( JackNetUnixSocket* socket ); - - //options management - int SetOption ( int level, int optname, const void* optval, socklen_t optlen ); - int GetOption ( int level, int optname, void* optval, socklen_t* optlen ); - - //timeout - int SetTimeOut ( int us ); - - //local loop - int SetLocalLoop(); - - //network operations - int SendTo ( const void* buffer, size_t nbytes, int flags ); - int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip ); - int Send ( const void* buffer, size_t nbytes, int flags ); - int RecvFrom ( void* buffer, size_t nbytes, int flags ); - int Recv ( void* buffer, size_t nbytes, int flags ); - int CatchHost ( void* buffer, size_t nbytes, int flags ); - - //error management - net_error_t GetError(); + private: + int fSockfd; + int fPort; + + struct sockaddr_in fSendAddr; + struct sockaddr_in fRecvAddr; + public: + JackNetUnixSocket(); + JackNetUnixSocket ( const char* ip, int port ); + JackNetUnixSocket ( const JackNetUnixSocket& ); + ~JackNetUnixSocket(); + + JackNetUnixSocket& operator= ( const JackNetUnixSocket& socket ); + + //socket management + int NewSocket(); + int Bind(); + int BindWith ( const char* ip ); + int BindWith ( int port ); + int Connect(); + int ConnectTo ( const char* ip ); + void Close(); + void Reset(); + bool IsSocket(); + + //IP/PORT management + void SetPort ( int port ); + int GetPort(); + + //address management + int SetAddress ( const char* ip, int port ); + char* GetSendIP(); + char* GetRecvIP(); + + //utility + int GetName ( char* name ); + int JoinMCastGroup ( const char* mcast_ip ); + void CopyParams ( JackNetUnixSocket* socket ); + + //options management + int SetOption ( int level, int optname, const void* optval, socklen_t optlen ); + int GetOption ( int level, int optname, void* optval, socklen_t* optlen ); + + //timeout + int SetTimeOut ( int us ); + + //local loop + int SetLocalLoop(); + + //network operations + int SendTo ( const void* buffer, size_t nbytes, int flags ); + int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip ); + int Send ( const void* buffer, size_t nbytes, int flags ); + int RecvFrom ( void* buffer, size_t nbytes, int flags ); + int Recv ( void* buffer, size_t nbytes, int flags ); + int CatchHost ( void* buffer, size_t nbytes, int flags ); + + //error management + net_error_t GetError(); }; } diff --git a/common/JackPlatformNetSocket.h b/common/JackPlatformNetSocket.h index 79518074..c17a5f0f 100644 --- a/common/JackPlatformNetSocket.h +++ b/common/JackPlatformNetSocket.h @@ -38,11 +38,11 @@ namespace Jack { #if defined(__APPLE__) || defined(__linux__) - typedef JackNetUnixSocket JackNetSocket; + typedef JackNetUnixSocket JackNetSocket; #endif #ifdef WIN32 - typedef JackNetWinSocket JackNetSocket; + typedef JackNetWinSocket JackNetSocket; #endif } // end of namespace diff --git a/windows/JackNetWinSocket.cpp b/windows/JackNetWinSocket.cpp index e7185790..9991483a 100644 --- a/windows/JackNetWinSocket.cpp +++ b/windows/JackNetWinSocket.cpp @@ -39,63 +39,63 @@ namespace Jack char* msg; } NetErrorList[] = { - E(0, "No error"), - E(WSAEINTR, "Interrupted system call"), - E(WSAEBADF, "Bad file number"), - E(WSAEACCES, "Permission denied"), - E(WSAEFAULT, "Bad address"), - E(WSAEINVAL, "Invalid argument"), - E(WSAEMFILE, "Too many open sockets"), - E(WSAEWOULDBLOCK, "Operation would block"), - E(WSAEINPROGRESS, "Operation now in progress"), - E(WSAEALREADY, "Operation already in progress"), - E(WSAENOTSOCK, "Socket operation on non-socket"), - E(WSAEDESTADDRREQ, "Destination address required"), - E(WSAEMSGSIZE, "Message too long"), - E(WSAEPROTOTYPE, "Protocol wrong type for socket"), - E(WSAENOPROTOOPT, "Bad protocol option"), - E(WSAEPROTONOSUPPORT, "Protocol not supported"), - E(WSAESOCKTNOSUPPORT, "Socket type not supported"), - E(WSAEOPNOTSUPP, "Operation not supported on socket"), - E(WSAEPFNOSUPPORT, "Protocol family not supported"), - E(WSAEAFNOSUPPORT, "Address family not supported"), - E(WSAEADDRINUSE, "Address already in use"), - E(WSAEADDRNOTAVAIL, "Can't assign requested address"), - E(WSAENETDOWN, "Network is down"), - E(WSAENETUNREACH, "Network is unreachable"), - E(WSAENETRESET, "Net connection reset"), - E(WSAECONNABORTED, "Software caused connection abort"), - E(WSAECONNRESET, "Connection reset by peer"), - E(WSAENOBUFS, "No buffer space available"), - E(WSAEISCONN, "Socket is already connected"), - E(WSAENOTCONN, "Socket is not connected"), - E(WSAESHUTDOWN, "Can't send after socket shutdown"), - E(WSAETOOMANYREFS, "Too many references, can't splice"), - E(WSAETIMEDOUT, "Connection timed out"), - E(WSAECONNREFUSED, "Connection refused"), - E(WSAELOOP, "Too many levels of symbolic links"), - E(WSAENAMETOOLONG, "File name too long"), - E(WSAEHOSTDOWN, "Host is down"), - E(WSAEHOSTUNREACH, "No route to host"), - E(WSAENOTEMPTY, "Directory not empty"), - E(WSAEPROCLIM, "Too many processes"), - E(WSAEUSERS, "Too many users"), - E(WSAEDQUOT, "Disc quota exceeded"), - E(WSAESTALE, "Stale NFS file handle"), - E(WSAEREMOTE, "Too many levels of remote in path"), - E(WSASYSNOTREADY, "Network system is unavailable"), - E(WSAVERNOTSUPPORTED, "Winsock version out of range"), - E(WSANOTINITIALISED, "WSAStartup not yet called"), - E(WSAEDISCON, "Graceful shutdown in progress"), - E(WSAHOST_NOT_FOUND, "Host not found"), - E(WSANO_DATA, "No host data of that type was found"), + E ( 0, "No error" ), + E ( WSAEINTR, "Interrupted system call" ), + E ( WSAEBADF, "Bad file number" ), + E ( WSAEACCES, "Permission denied" ), + E ( WSAEFAULT, "Bad address" ), + E ( WSAEINVAL, "Invalid argument" ), + E ( WSAEMFILE, "Too many open sockets" ), + E ( WSAEWOULDBLOCK, "Operation would block" ), + E ( WSAEINPROGRESS, "Operation now in progress" ), + E ( WSAEALREADY, "Operation already in progress" ), + E ( WSAENOTSOCK, "Socket operation on non-socket" ), + E ( WSAEDESTADDRREQ, "Destination address required" ), + E ( WSAEMSGSIZE, "Message too long" ), + E ( WSAEPROTOTYPE, "Protocol wrong type for socket" ), + E ( WSAENOPROTOOPT, "Bad protocol option" ), + E ( WSAEPROTONOSUPPORT, "Protocol not supported" ), + E ( WSAESOCKTNOSUPPORT, "Socket type not supported" ), + E ( WSAEOPNOTSUPP, "Operation not supported on socket" ), + E ( WSAEPFNOSUPPORT, "Protocol family not supported" ), + E ( WSAEAFNOSUPPORT, "Address family not supported" ), + E ( WSAEADDRINUSE, "Address already in use" ), + E ( WSAEADDRNOTAVAIL, "Can't assign requested address" ), + E ( WSAENETDOWN, "Network is down" ), + E ( WSAENETUNREACH, "Network is unreachable" ), + E ( WSAENETRESET, "Net connection reset" ), + E ( WSAECONNABORTED, "Software caused connection abort" ), + E ( WSAECONNRESET, "Connection reset by peer" ), + E ( WSAENOBUFS, "No buffer space available" ), + E ( WSAEISCONN, "Socket is already connected" ), + E ( WSAENOTCONN, "Socket is not connected" ), + E ( WSAESHUTDOWN, "Can't send after socket shutdown" ), + E ( WSAETOOMANYREFS, "Too many references, can't splice" ), + E ( WSAETIMEDOUT, "Connection timed out" ), + E ( WSAECONNREFUSED, "Connection refused" ), + E ( WSAELOOP, "Too many levels of symbolic links" ), + E ( WSAENAMETOOLONG, "File name too long" ), + E ( WSAEHOSTDOWN, "Host is down" ), + E ( WSAEHOSTUNREACH, "No route to host" ), + E ( WSAENOTEMPTY, "Directory not empty" ), + E ( WSAEPROCLIM, "Too many processes" ), + E ( WSAEUSERS, "Too many users" ), + E ( WSAEDQUOT, "Disc quota exceeded" ), + E ( WSAESTALE, "Stale NFS file handle" ), + E ( WSAEREMOTE, "Too many levels of remote in path" ), + E ( WSASYSNOTREADY, "Network system is unavailable" ), + E ( WSAVERNOTSUPPORTED, "Winsock version out of range" ), + E ( WSANOTINITIALISED, "WSAStartup not yet called" ), + E ( WSAEDISCON, "Graceful shutdown in progress" ), + E ( WSAHOST_NOT_FOUND, "Host not found" ), + E ( WSANO_DATA, "No host data of that type was found" ), { -1, NULL }, }; EXPORT const char* PrintError ( int error ) { int i; - for ( i = 0; NetErrorList[i].code >= 0; ++i) + for ( i = 0; NetErrorList[i].code >= 0; ++i ) { if ( error == NetErrorList[i].code ) return NetErrorList[i].msg; @@ -267,12 +267,12 @@ namespace Jack //options************************************************************************************************************ int JackNetWinSocket::SetOption ( int level, int optname, const void* optval, SOCKLEN optlen ) { - return setsockopt ( fSockfd, level, optname, static_cast(optval), optlen ); + return setsockopt ( fSockfd, level, optname, static_cast ( optval ), optlen ); } int JackNetWinSocket::GetOption ( int level, int optname, void* optval, SOCKLEN* optlen ) { - return getsockopt ( fSockfd, level, optname, static_cast(optval), optlen ); + return getsockopt ( fSockfd, level, optname, static_cast ( optval ), optlen ); } //tiemout************************************************************************************************************ @@ -295,7 +295,7 @@ namespace Jack //network operations************************************************************************************************* int JackNetWinSocket::SendTo ( const void* buffer, size_t nbytes, int flags ) { - return sendto ( fSockfd, reinterpret_cast(buffer), nbytes, flags, reinterpret_cast ( &fSendAddr ), sizeof ( SOCKADDR ) ); + return sendto ( fSockfd, reinterpret_cast ( buffer ), nbytes, flags, reinterpret_cast ( &fSendAddr ), sizeof ( SOCKADDR ) ); } int JackNetWinSocket::SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip ) @@ -306,50 +306,50 @@ namespace Jack int JackNetWinSocket::Send ( const void* buffer, size_t nbytes, int flags ) { - return send ( fSockfd, reinterpret_cast(buffer), nbytes, flags ); + return send ( fSockfd, reinterpret_cast ( buffer ), nbytes, flags ); } int JackNetWinSocket::RecvFrom ( void* buffer, size_t nbytes, int flags ) { SOCKLEN addr_len = sizeof ( SOCKADDR ); - return recvfrom ( fSockfd, reinterpret_cast(buffer), nbytes, flags, reinterpret_cast ( &fRecvAddr ), &addr_len ); + return recvfrom ( fSockfd, reinterpret_cast ( buffer ), nbytes, flags, reinterpret_cast ( &fRecvAddr ), &addr_len ); } int JackNetWinSocket::Recv ( void* buffer, size_t nbytes, int flags ) { - return recv ( fSockfd, reinterpret_cast(buffer), nbytes, flags ); + return recv ( fSockfd, reinterpret_cast ( buffer ), nbytes, flags ); } int JackNetWinSocket::CatchHost ( void* buffer, size_t nbytes, int flags ) { SOCKLEN addr_len = sizeof ( SOCKADDR ); - return recvfrom ( fSockfd, reinterpret_cast(buffer), nbytes, flags, reinterpret_cast ( &fSendAddr ), &addr_len ); + return recvfrom ( fSockfd, reinterpret_cast ( buffer ), nbytes, flags, reinterpret_cast ( &fSendAddr ), &addr_len ); } net_error_t JackNetWinSocket::GetError() { switch ( NET_ERROR_CODE ) { - case WSABASEERR: - return NET_NO_ERROR; - case WSAETIMEDOUT: - return NET_NO_DATA; - case WSAEWOULDBLOCK: - return NET_NO_DATA; - case WSAECONNREFUSED: - return NET_CONN_ERROR; - case WSAECONNRESET: - return NET_CONN_ERROR; - case WSAEACCES: - return NET_CONN_ERROR; - case WSAECONNABORTED: - return NET_CONN_ERROR; - case WSAEHOSTDOWN: - return NET_CONN_ERROR; - case WSAEHOSTUNREACH: - return NET_CONN_ERROR; - default: - return NET_OP_ERROR; + case WSABASEERR: + return NET_NO_ERROR; + case WSAETIMEDOUT: + return NET_NO_DATA; + case WSAEWOULDBLOCK: + return NET_NO_DATA; + case WSAECONNREFUSED: + return NET_CONN_ERROR; + case WSAECONNRESET: + return NET_CONN_ERROR; + case WSAEACCES: + return NET_CONN_ERROR; + case WSAECONNABORTED: + return NET_CONN_ERROR; + case WSAEHOSTDOWN: + return NET_CONN_ERROR; + case WSAEHOSTUNREACH: + return NET_CONN_ERROR; + default: + return NET_OP_ERROR; } } } diff --git a/windows/JackNetWinSocket.h b/windows/JackNetWinSocket.h index 6cdb2d56..79b36e4c 100644 --- a/windows/JackNetWinSocket.h +++ b/windows/JackNetWinSocket.h @@ -41,63 +41,63 @@ namespace Jack //JeckNetWinSocket*************************************************************************** class EXPORT JackNetWinSocket { - private: - int fSockfd; - int fPort; - SOCKADDR_IN fSendAddr; - SOCKADDR_IN fRecvAddr; - public: - JackNetWinSocket(); - JackNetWinSocket ( const char* ip, int port ); - JackNetWinSocket ( const JackNetWinSocket& ); - ~JackNetWinSocket(); - - JackNetWinSocket& operator= ( const JackNetWinSocket& ); - - //socket management - int NewSocket(); - int Bind(); - int BindWith ( const char* ip ); - int BindWith ( int port ); - int Connect(); - int ConnectTo ( const char* ip ); - void Close(); - void Reset(); - bool IsSocket(); - - //IP/PORT management - void SetPort ( int port ); - int GetPort(); - - //address management - int SetAddress ( const char* ip, int port ); - char* GetSendIP(); - char* GetRecvIP(); - - //utility - int GetName ( char* name ); - int JoinMCastGroup ( const char* mcast_ip ); - - //options management - int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen ); - int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen ); - - //timeout - int SetTimeOut ( int usec ); - - //local loop - int SetLocalLoop(); - - //network operations - int SendTo ( const void* buffer, size_t nbytes, int flags ); - int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip ); - int Send ( const void* buffer, size_t nbytes, int flags ); - int RecvFrom ( void* buffer, size_t nbytes, int flags ); - int Recv ( void* buffer, size_t nbytes, int flags ); - int CatchHost ( void* buffer, size_t nbytes, int flags ); - - //error management - net_error_t GetError(); + private: + int fSockfd; + int fPort; + SOCKADDR_IN fSendAddr; + SOCKADDR_IN fRecvAddr; + public: + JackNetWinSocket(); + JackNetWinSocket ( const char* ip, int port ); + JackNetWinSocket ( const JackNetWinSocket& ); + ~JackNetWinSocket(); + + JackNetWinSocket& operator= ( const JackNetWinSocket& ); + + //socket management + int NewSocket(); + int Bind(); + int BindWith ( const char* ip ); + int BindWith ( int port ); + int Connect(); + int ConnectTo ( const char* ip ); + void Close(); + void Reset(); + bool IsSocket(); + + //IP/PORT management + void SetPort ( int port ); + int GetPort(); + + //address management + int SetAddress ( const char* ip, int port ); + char* GetSendIP(); + char* GetRecvIP(); + + //utility + int GetName ( char* name ); + int JoinMCastGroup ( const char* mcast_ip ); + + //options management + int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen ); + int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen ); + + //timeout + int SetTimeOut ( int usec ); + + //local loop + int SetLocalLoop(); + + //network operations + int SendTo ( const void* buffer, size_t nbytes, int flags ); + int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip ); + int Send ( const void* buffer, size_t nbytes, int flags ); + int RecvFrom ( void* buffer, size_t nbytes, int flags ); + int Recv ( void* buffer, size_t nbytes, int flags ); + int CatchHost ( void* buffer, size_t nbytes, int flags ); + + //error management + net_error_t GetError(); }; }