Changeset 8cf56a5 in nscp


Ignore:
Timestamp:
02/16/05 23:28:38 (8 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
402f042
Parents:
ac676a8
Message:

port is now loaded from the settings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TCPSocketResponder.cpp

    ra0528c4 r8cf56a5  
    44#include "NSClient++.h" 
    55#include "TCPSocketResponder.h" 
     6#include "Settings.h" 
    67 
    78extern NSClient mainClient; 
     
    7980  local.sin_family=AF_INET; 
    8081  local.sin_addr.s_addr=INADDR_ANY; 
    81   local.sin_port=htons((u_short)1234); 
     82  local.sin_port=htons(static_cast<u_short>(Settings::getInstance()->getInt("generic", "port", DEFAULT_TCP_PORT))); 
    8283  server=socket(AF_INET,SOCK_STREAM,0); 
    8384  if(server==INVALID_SOCKET) { 
     
    102103  while(isRunning()) { 
    103104    client=accept(server, (struct sockaddr*)&from,&fromlen); 
    104     char *buff = new char[RECV_BUFFER_LEN+1]; 
    105     int n=recv(client,buff,RECV_BUFFER_LEN,0); 
    106     if ((n!=SOCKET_ERROR )&&(n > 0)&&(n < RECV_BUFFER_LEN)) { 
    107       buff[n] = '\0'; 
    108       LOG_DEBUG("Incoming data: "); 
    109       LOG_DEBUG(buff); 
    110       std::string ret = parseCommand(buff); 
    111       LOG_DEBUG("Outgoing data: "); 
    112       LOG_DEBUG(ret.c_str()); 
    113       send(client, ret.c_str(), ret.length(), 0); 
    114     } else { 
    115       std::string str = "ERROR: Unknown socket error"; 
    116       send(client,str.c_str(),str.length(),0); 
     105    if (client != INVALID_SOCKET) { 
     106      LOG_ERROR_STD("Accept returned: " + strEx::itos((DWORD)client)); 
     107      char *buff = new char[RECV_BUFFER_LEN+1]; 
     108      int n=recv(client,buff,RECV_BUFFER_LEN,0); 
     109      if ((n!=SOCKET_ERROR )&&(n > 0)&&(n < RECV_BUFFER_LEN)) { 
     110        buff[n] = '\0'; 
     111        LOG_DEBUG("Incoming data: "); 
     112        LOG_DEBUG(buff); 
     113        std::string ret = parseCommand(buff); 
     114        LOG_DEBUG("Outgoing data: "); 
     115        LOG_DEBUG(ret.c_str()); 
     116        send(client, ret.c_str(), ret.length(), 0); 
     117      } else { 
     118        std::string str = "ERROR: Unknown socket error"; 
     119        send(client,str.c_str(),str.length(),0); 
     120      } 
     121      delete [] buff; 
     122      closesocket(client); 
    117123    } 
    118     delete [] buff; 
    119     closesocket(client); 
    120124  } 
    121125  closesocket(server); 
Note: See TracChangeset for help on using the changeset viewer.