Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >Application Programming


    

Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006


Progressive master basic categories : Network Programming in C + +, virtual, static, thread function

Certainly not experts can come ah ^_^

This is the type of Anxiang write a network terminal, the terminal can run on different user-defined communication protocols.
So let users use : a new terminal, and then the terminal. Run (); On it. Run premise of this approach is heavy, like Delphi TThread.

The idea is this : in the base class constructor function based on the traditional parameters is built over a TCP or UDP socket, after creating successful threads, thread is the Run function (), as the base class does not know how and servers, so it is a sham or purely nominal.

Question : All members are required function is static or Tomomoto can function as a thread. Static bars, it can not be guilty (virtual); If you, it is Run (); Instead terminal.Run (); Who Run users may in the end () are doubts.

Another target : To ensure the independence of the terminal (to be done to test virtual terminals), so I do not want to re-establish a connecting thread, terminal objects. Let terminal objects, thread and socket with the same students die.

Write a bit awkward catalog, sorry.

Thank you! !

Why must run as a thread function?

I Am Not experts, the trouble is coming


[code]
14.00 Terminal
{
Private :
Staic pthread_key_t __key;
Pthread_t __thid;
Void* __start () (void* p) ((Terminal*) p->run () ;}//POSIX
Public :
Void start () {pthread_create (&__thid, NULL, __start (void*) this) type of object ;}// son started calling thread
Public :
Virtual void run () =0;// virtual function, the function of a specific sub-category of Heavy
};

14.00 TCP_Terminal:public Terminal
{
Void run () {}
};

Int main ()
{
Terminal* terminal=new TCP_Terminal;
Terminal->start ();
}
[/code]

Not simple to achieve.
As you say, not as pthread_create virtual function parameters, which can be used in whole or function defined in a static-type function.
I do not master, code-written chaos, for reference purposes only, and the release of some data needs initialization.

TO:deathbravo
-->

.
To users, Oh, I is the current and convenient. Thread one to use as a terminal, or vice versa, when the terminal thread. However, thread and socket in the building of a new terminal when it was targeted by the base class to do the work. For instance, if some heavy-category run () This function, and new MyTerminal (127.0.0.1,8060 "TCP"); Became, How simple?


Thank you hezhiroy (ladies).
Anjiu perception find ways! In fact _beginthread () function parameters : the requirements are intended to address a "defining the address" space, and we can do something in the use of language rules "drift" -- to achieve its goal of the compiler is dead, is alive. This is what I understand.
Younger C + + experience, there will be even more questions for the future! CU-diving four years to go!

To:hezhiroy
[QUOTE]
Void * __start () (void* p) ((Terminal*) p->run () ;}//POSIX
[/QUOTE]
Do you mean that it is the definition of a function pointer __start? , At a function void func (void 6-12) ((Terminal*) p->run () ;}?

-->

I do not know how to make, but I feel like I short while ago to see the libjingle Lane and the TCP or UDP socket creation and operation of the thread
Some similarities
Can refer to, but not exactly the same and not lz demand.
Em03 em03 : : : : : : em03

TO:hezhiroy (ladies)
I VC6 on your code changed a bit, with a static, like this :
[QUOTE]class Terminal
{
Private :
Static void __start (6-12 void) (((Terminal*) p) ->run (); )
Public :
Void start () (_beginthread (__start, 0, (void*) this) ;}
Public :
Virtual void run () =0;// virtual function, the function of a specific sub-category of Heavy
};

14.00 TCP_Terminal:public Terminal
{
Void run () (cout "" "TCP_Terminal 's run!" "" endl;)
};

Int main ()
{
TCP_Terminal* terminal=new TCP_Terminal;
Cout "" "before\n";
Terminal->start ();
Sleep (3000);
Cout "" "after\n";
Return 0
}[/QUOTE]
The question now is, the category may find its use ->start () does not directly own just as the heavy ->run (); He therefore directly run (), so it can not be activated thread, can prevent him from doing so, at the same time, allowing him to be heavy run ()?

Oh, I can, if deployed ->run (); Compiler on the links, however, are not members of the private visit.



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com