Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 20:52

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C++] Problem with threading

Discussion on [C++] Problem with threading within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
[C++] Problem with threading

Actually the problem is more like with passing a function as pointer to the CreateThread or _beginthreadex,

PHP Code:
BOOL Connect()
    {
        if(
m_Enabled != TRUE)
            return 
FALSE;

        
sockaddr_in addr;
        
addr.sin_family AF_INET;
        
addr.sin_port htons(m_RemotePort);
        
addr.sin_addr.S_un.S_addr inet_addr(m_RemoteIP);
        if(
connect(m_Connection, (sockaddr*)&addrsizeof(addr)) == INVALID_SOCKET)
        {
            
WSACleanup();
            
m_Enabled FALSE;
            return 
FALSE;
        }
        
hRecvThread = (HANDLE)_beginthreadex(NULL0, &AsyncRecvthisNULLNULL);
        return 
TRUE;
    }
    
unsigned __stdcall AsyncRecv(voidpArgs) {

        return 
0;
    } 
I'm not sure even if the AsyncRecv is declared right, it's a example that I found on the net. The error I'm getting is
PHP Code:
error C2276'&' illegal operation on bound member function expression 
Help is much appreciated.
tanelipe is offline  
Old 05/17/2009, 16:44   #2
 
clintonselke's Avatar
 
elite*gold: 0
Join Date: Feb 2007
Posts: 348
Received Thanks: 2,175
For function pointers u don't need the &. You only need to drop its () and parameters to make it a pointer. (But it should still be working w/ the & for most compliers), Also make sure u prototype your function if ur gonna use it in a line before the line in which it is defined.
clintonselke is offline  
Old 05/17/2009, 16:55   #3
 
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
I got it working now >_>

PHP Code:
BOOL Connect()
    {
        if(
m_Enabled != TRUE)
            return 
FALSE;

        
sockaddr_in addr;
        
addr.sin_family AF_INET;
        
addr.sin_port htons(m_RemotePort);
        
addr.sin_addr.S_un.S_addr inet_addr(m_RemoteIP);
        if(
connect(m_Connection, (sockaddr*)&addrsizeof(addr)) == INVALID_SOCKET)
        {
            
WSACleanup();
            
m_Enabled FALSE;
            return 
FALSE;
        }
        
hRecvThread CreateThread(NULL0, (LPTHREAD_START_ROUTINE)AsyncRecvthisNULLNULL);
        return 
TRUE;
    }
    static 
DWORD WINAPI AsyncRecv(voidpArg) {
        
ClientSocketclient = (ClientSocket*)pArg;
        while(
client->m_Enabled)
        {
            
char buffer[4096];
            
int len recv(client->m_Connectionbuffersizeof(buffer), 0);    
            if(
len 0
            {
                
client->m_Enabled FALSE;
            }
            if(
OnClientReceive != NULL)
                
OnClientReceive(clientbuffer);
            
Sleep(1);
        }
        
CloseHandle(client->hRecvThread);
        return 
0;
    } 
tanelipe is offline  
Reply


Similar Threads Similar Threads
[Release]Make the threading system better.[5165 NewestCOServer]
09/13/2010 - CO2 PServer Guides & Releases - 10 Replies
Okay so, I was bored so I thought I would release some easy shiz. Credits to Impulse for his Thread.cs :) Goto Program.cs find Console.WriteLine("The server is ready for connections."); abit under that is the threading system. It's like
[Problem] Problem with server starting - cannot find quest index for PaxHeader
12/22/2009 - Metin2 Private Server - 1 Replies
Hello! I have this same problem as here when i'm starting my server: http://www.elitepvpers.com/forum/metin2-pserver-di scussions-questions/307143-metin2-serverfiles-ques t-index-fehler.html But I didn't know the answer.. how to repair this? Greetings
[C#] Cross-Threading ?
10/14/2008 - .NET Languages - 7 Replies
Hello, Is there a flag or whatever that lets me use crossthreading freely? Without the help of a Workerthread. Whenever I try to change a variable it doesn't let me because Crossthreading isn't safe (eg. accessing the variables from other threads), but It's also hard to find a solution for this. I'm starting another thread that contains a function to download the source code of another page and process the wanted information into variables, however I cannot do that with a thread. The only...



All times are GMT +1. The time now is 20:53.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.