Important Bug fixes:

- Remote Client connect not working properly
  - Set Client Port no on connect
  - Correctly handle create failure
  - Show error on fail
- Input() fail to transfer data if Handle & Channel not same name
  - Search for linked handles
This commit is contained in:
Charl Wentzel
2017-08-18 09:12:55 +02:00
parent 18b487cbdd
commit 2830b8dd6d

View File

@@ -733,7 +733,8 @@ int CSelectableCore::OpenRemoteClientSocket( THandle * Handle )
{ {
THandle ** RemoteClient; THandle ** RemoteClient;
int ClientFD; int ClientFD;
char ClientAddress[100]; char ClientAddress[50];
char ClientPort[20];
char ClientName[100]; char ClientName[100];
socklen_t addr_len; socklen_t addr_len;
@@ -767,6 +768,8 @@ int CSelectableCore::OpenRemoteClientSocket( THandle * Handle )
// Return client address // Return client address
strcpy( ClientAddress, inet_ntoa(address.sin_addr) ); strcpy( ClientAddress, inet_ntoa(address.sin_addr) );
sprintf( ClientPort, "%d", ntohs(address.sin_port) );
// Get end of client list // Get end of client list
RemoteClient = &FirstHandle; RemoteClient = &FirstHandle;
@@ -777,7 +780,10 @@ int CSelectableCore::OpenRemoteClientSocket( THandle * Handle )
// Create Remote Client Handle // Create Remote Client Handle
sprintf( ClientName, "%s-%d", Handle->Name, ClientFD ); sprintf( ClientName, "%s-%d", Handle->Name, ClientFD );
*RemoteClient = CreateHandle( ClientName, false ); *RemoteClient = CreateHandle( ClientName, false );
SetSocketHandle( *RemoteClient, ctRemoteClient, ClientAddress, 0, Handle->KeepAlive ); if (!SetSocketHandle( *RemoteClient, ctRemoteClient, ClientAddress, ClientPort, Handle->KeepAlive )) {
if (Log) Log->Message( LogLevel, dlMedium, "%s: Handle '%s' - TCP Server failed to configure Remote TCP Client connection (%s)", Name, Handle->Name, strerror(errno) );
return -1;
}
// Copy Parent Buffer setup // Copy Parent Buffer setup
SetBuffers( *RemoteClient, ((Handle->InBuffer)? Handle->InBuffer->Size() : 0), SetBuffers( *RemoteClient, ((Handle->InBuffer)? Handle->InBuffer->Size() : 0),
@@ -1064,13 +1070,15 @@ bool CSelectableCore::Read( THandle * Handle )
{ {
// Incoming client request // Incoming client request
ClientFD = OpenRemoteClientSocket( Handle ); ClientFD = OpenRemoteClientSocket( Handle );
if (ClientFD != -1) { if (ClientFD == -1) {
// Add to Select Lists return false;
if (Selector) {
Selector->Add( ClientFD, true, true, this );
}
return true;
} }
// Add to Select Lists
if (Selector) {
Selector->Add( ClientFD, true, true, this );
}
return true;
} }
else if ((Handle->Type == ctRemoteClient) || (Handle->Type == ctClient)) else if ((Handle->Type == ctRemoteClient) || (Handle->Type == ctClient))
{ {
@@ -1310,13 +1318,19 @@ int CSelectableCore::Input( const char * ChannelName, const char * Data, int Len
return 0; return 0;
} }
// Get File handle // Find Linked handle
if (!(Handle = GetHandle( ChannelName ))) { Handle = FirstHandle;
while( Handle && (!Handle->Channel || strcasecmp( ChannelName, Handle->Channel->Name ))) {
Handle = Handle->Next;
}
// Check if any handle found
if (!Handle) {
// Handle not found // Handle not found
if (Log) Log->Message( LogLevel, dlHigh, "%s: Channel '%s' - Input rejected, Handle not found", Name, ChannelName ); if (Log) Log->Message( LogLevel, dlHigh, "%s: Channel '%s' - Input rejected, Handle not found", Name, ChannelName );
return 0; return 0;
} }
else if (Handle->Channel && !Handle->Channel->InputEnabled) { else if (!Handle->Channel->InputEnabled) {
// Handle is not open // Handle is not open
if (Log) Log->Message( LogLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel input disabled", Name, ChannelName ); if (Log) Log->Message( LogLevel, dlHigh, "%s: Channel '%s' - Input rejected, Channel input disabled", Name, ChannelName );
return 0; return 0;