Hi,
I've some issues with the GNU Pth and a multi-threaded, multi-servers,
multi-sessions C++ library.
This library is in a very very early stage but i need to have the threads
support running...
libyourserver is primary developped as the network layer of an RDBM which
comes from a school project.
I need you to resolv this problem ;)
The concept is simple :
- one or more servers threaded from a main application
- one or more sessions threaded by each server
- sessions can be :
- accept waiting sessions (intermediate sessions)
- simple clients sessions (old accept waiting sessions)
- server to server communication sessions (old accept waiting sessions)
*******************************************************************************
-----------
| Session B | --------------
-----.----- | Server |Two| |
/ -.------------
----------- / . /
| Session A | / . /
-----.----- / . /
| / . /
| / /
-----.------.-------.
| | -----------
| Server |One| |----------------| Session C |
| | -----------
----.----------.---.-
. | \
. --------.-------------
. | Intermediate session |
. ----------------------
. \
---------------------.--------- .----------
| | | Session D |
| | -----------
| Application |
| | -----------
| | | Session E |
---------------------.--------- .----------
. /
. -----------------------
. | Intermediate Session |
. --------.--------------
. | /
-----.----------.---.
| | -----------
| Server |Two| .-----------------| Session F |
| | -----------
-----.-----.---------
| \ \
| \ .
-----.----- \ \
| Session H | \ .
----------- \ \
\ .
-----.----- \
| Session G | .
----------- \
-.------------
| Server |One| |
--------------
Legend :
--------
. . . . . . . . = server threads
. - - - - - - . = session threads
- . - . - . - . = server2server session threads
******************************************************************************
Since my library is written in C++, i've written two wrappers :
******************************************************************************
// Make a thread to encapsulate a server instance
void*
ysrv_wrap_spawn_server (void* _params)
{
server_spawn_params* params = (server_spawn_params*) _params;
*params->server = new Server (params->config,
params->eta_client,
params->eta_server,
params->retry);
return NULL;
}
// -----
// Make a thread to encapsulate a session instance
void*
ysrv_wrap_spawn_session (void* _params)
{
session_spawn_params* params = (session_spawn_params*) _params;
*params->session = new Session (params->server,
params->socket,
params->config,
params->nb_sessions,
params->eta_client,
params->eta_server,
params->retry);
return NULL;
}
*******************************************************************************
a call example :
params->server = &new_server->server;
params->config = this->config;
params->eta_client = _ETA_client_func;
params->eta_server = _ETA_server_func;
params->retry = _retry_msg;
pth_attr_set(attr, PTH_ATTR_JOINABLE, FALSE);
pth_attr_set(attr, PTH_ATTR_NAME, "Server");
(void) pth_spawn (attr, ysrv_wrap_spawn_server, params);
with the params structure :
// Server instance creation parameters
typedef struct _server_spawn_params server_spawn_params;
struct _server_spawn_params
{
SESSION_FUNC((*eta_client));
SESSION_FUNC((*eta_server));
char* retry;
Server** server;
s_config* config;
};
*******************************************************************************
session building steps :
1/ Make an application instance
|Application|
2/ Create a first server - initialize network, listen
|Application| -thread-> |server|
2/ The server creation creates a new session instance, to accept connections
|Application| -thread-> |server| -thread-> |session1-accept|
3/ On incoming connection, session-accept is linked to the server as an
etablished session, by Server::attach_session (Session*), who creates a
new session-accept
|Application| -thread-> |server| -thread-> |session2-accept|
||
thread
||
\/
|session1-I/O|
ALL threading processes are made by the two wrappers
void* ysrv_wrap_spawn_server (void*);
void* ysrv_wrap_spawn_session (void*);
*******************************************************************************
Then, i've got some issues :
consider that when a session is linked to the server, after successful accept,
the only next instructions which are executed are :
pth_write (this->sock, "\n\nYou're connected...\n\n\n", 25);
pth_sleep (5);
- if i put (for testing purpose only) a 'while (1) pth_sleep (5)' after each
pth_spawn call, or only at the end of the wrappers, threading is
well done but pth_write is not executed :
mglcel@amnesty include-> telnet localhost 4242
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
and freeze..
- if i don't write the pth_sleep (5) after the pth_write (), and no pth_sleep
while loop after each pth_spawn, all is ok but not very interesting..
- if i only write the pth_sleep (5) after the pth_write (), the first connexion
is accepted and pth_write executed correctly but the program segfault on the
next accept.
Have you some ideas to proceed or a few links or source code
to help me please ?
If you have time to see my source code, i join it with this mail.
You could find the class hierarchie in libyourserver/src/OOTREE.
The library applciation cab be found in yourSQL/src/yoursqld
Thanks a lot for everything you can do to help me ;)
---
DIAS DA SILVA Loic (Mglcel) <[EMAIL PROTECTED]>
It's simply unbelievable how much energy and creativity people have
invested into creating contradictory, bogus and stupid licenses...
--- Sven Rudolph about licences in debian/non-free.
When code matters more than commericials
--- GNU/Debian slogan ---
libyourserver-yourSQLd.tar.gz