Quantcast

Jump to content

» «
Photo

help with a server written in c++

6 replies to this topic
Samutz
  • Samutz

    Undefined index: member_title in user_profile.php on line 1012

  • Members
  • Joined: 17 Sep 2003
  • Unknown
  • Contribution Award [SnP Site Design]

#1

Posted 03 May 2005 - 05:50 AM Edited by Samutz, 03 May 2005 - 05:29 PM.

I've got this server program I'm trying to compile on linux, but when I try to, I get this error.

I don't know that much about C++ and I sure as hell don't know what this function does, so I don't know if this is an easy fix, but if it is, can someone help me?

CODE
g++ -O2 -DSOCKLEN_T=socklen_t -Wno-deprecated -g -DLINUX -DDEBUG -I/usr/include/mysql -c convertedclasses.cpp
convertedclasses.cpp: In member function `JString TSocket::Read()':
convertedclasses.cpp:569: invalid conversion from `int*' to `socklen_t*'
make: *** [convertedclasses.o] Error 1


Edit:
Here's line 569:
CODE
 if (udp) bytesread = recvfrom(sock,xfilebuf,8192,0,(struct sockaddr *)&udpsender,&addr_len);


Here's the function out of convertedclasses.cpp:
CODE
JString TSocket::Read() {
if (!sock) return JString();
JString buffer;
long bytesread;
       while (true) {  
    if (!block || buffer.length()>0) {  
      fd_set set;  
      FD_ZERO(&set);  
      FD_SET(sock,&set);  
      struct timeval tm;  
      tm.tv_sec = 0;  
      tm.tv_usec = 0;  
      select(sock+1,&set,NULL,NULL,&tm);  
      if (!FD_ISSET(sock,&set)) return buffer;  
 }  

 int addr_len;
 if (udp) bytesread = recvfrom(sock,xfilebuf,8192,0,(struct sockaddr *)&udpsender,&addr_len);
 else bytesread = recv(sock,xfilebuf,8192,0);

        if (bytesread>0) {  
          buffer.addbuffer(xfilebuf,bytesread);  
   gotbytes += bytesread;
 } else if (bytesread==-1) {  
          #ifdef WINDOWS
     if (WSAGetLastError()) Close();
   #else
     if (errno) Close();  
   #endif
          if (!sock || !block) return buffer;  
        } else if (bytesread==0) {  
  Close();
                return buffer;
        }
 }
}

segosa
  • segosa

    Ghetto Star

  • BUSTED!
  • Joined: 15 May 2002

#2

Posted 03 May 2005 - 06:30 AM

And how are we meant to know what line 569 is? confused.gif


Samutz
  • Samutz

    Undefined index: member_title in user_profile.php on line 1012

  • Members
  • Joined: 17 Sep 2003
  • Unknown
  • Contribution Award [SnP Site Design]

#3

Posted 03 May 2005 - 06:32 AM

CODE
 if (udp) bytesread = recvfrom(sock,xfilebuf,8192,0,(struct sockaddr *)&udpsender,&addr_len);


I wasn't sure that it refered to the line since the line doesn't contain 'int' or 'socklen_t'.

segosa
  • segosa

    Ghetto Star

  • BUSTED!
  • Joined: 15 May 2002

#4

Posted 03 May 2005 - 05:09 PM

Sorry, I don't know. I've looked up recv and recvfrom but neither show any signs of socklen_t, and bytesread is a long on that line so nothing makes much sense.

Maybe someone else knows.

PatrickW
  • PatrickW

    GTA Juggernaut

  • Moderator
  • Joined: 07 Jan 2004
  • Netherlands
  • Best Script 2013 [DYOM]
    Best Script 2012 [DYOM]

#5

Posted 03 May 2005 - 07:38 PM

From the manual pages:
CODE

ssize_t recvfrom(int s , void * buf , size_t len ,  int flags , struct sockaddr * from , socklen_t * fromlen );
So the last param should be a socklen_t pointer instead of an int pointer.

To fix it, you should change line 568 and further into
to
CODE
socklen_t addr_len;
if (udp) {
   bytesread = recvfrom(sock,xfilebuf,8192,0,(struct sockaddr *)&udpsender,&addr_len);
}else {
   bytesread = recv(sock,xfilebuf,8192,0);
}


I've also inserted some '{}' to make it more readable and maintainable.

Samutz
  • Samutz

    Undefined index: member_title in user_profile.php on line 1012

  • Members
  • Joined: 17 Sep 2003
  • Unknown
  • Contribution Award [SnP Site Design]

#6

Posted 03 May 2005 - 08:00 PM

Thanks. It works past that part now, except that now I'm getting another error. But it's because my host is missing a library I need and they won't install it, so I'm going to have to wait til my new hosts get my account setup. confused.gif

segosa
  • segosa

    Ghetto Star

  • BUSTED!
  • Joined: 15 May 2002

#7

Posted 04 May 2005 - 06:24 AM

QUOTE (PatrickW @ May 3 2005, 21:38)
From the manual pages:
CODE

ssize_t recvfrom(int s , void * buf , size_t len ,  int flags , struct sockaddr * from , socklen_t * fromlen );
So the last param should be a socklen_t pointer instead of an int pointer.

To fix it, you should change line 568 and further into
to
CODE
socklen_t addr_len;
if (udp) {
   bytesread = recvfrom(sock,xfilebuf,8192,0,(struct sockaddr *)&udpsender,&addr_len);
}else {
   bytesread = recv(sock,xfilebuf,8192,0);
}


I've also inserted some '{}' to make it more readable and maintainable.

Hmm good point, I should have looked at Linux's manpages rather than MSDN >.<




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users