473,654 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert a single to multiuser.. in c++ program

OZ

the serproxy claim itself a multi-thread proxy thing.

I have sent email to write the original writer and there is no replay after
3 weeks. my configuration and setting are good.

http://www.lspace.nildram.co.uk/freeware.html

I installed it in rh 9.0

I found it is single user only.
do any one know how to change the single program in c program into a
multi-user?

/*
* main.c
*
* main module for serproxy
*
* (C)1999 Stefano Busti
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if defined(__UNIX_ _)
# include <unistd.h>
# include <fcntl.h>
# include <sys/time.h>
#elif defined(__WIN32 __)
# include <windows.h>
# include <io.h>
#endif

#include "sio.h"
#include "sock.h"
#include "pipe.h"
#include "thread.h"
#include "vlist.h"
#include "cfglib.h"
#include "config.h"
#include "error.h"

int readcfg(void);
void cleanup(void);
int waitclients(voi d);
thr_startfunc_t serve_pipe(void *data);
void debug(void);

#if defined(__UNIX_ _)
char cfgfile[] = "/etc/serproxy.cfg";
#elif defined(__WIN32 __)
char cfgfile[] = "serproxy.c fg";
#endif

cfg_s cfg;
vlist_s pipes;

int main(int argc, char **argv)
{
if (sock_start())
return -1;
vlist_init(&pip es, pipe_destroy);
cfg_init(&cfg, 0);
atexit(cleanup) ;
readcfg();
#ifdef DEBUG
debug();
#endif
waitclients();

return 0;
}

void cleanup(void)
{
cfg_cleanup(&cf g);
vlist_cleanup(& pipes);
sock_finish();
}

int readcfg(void)
{
char ports[BUFSIZ], *p;
int port;
pipe_s *pipe;
cfg_s local;
serialinfo_s sinfo;
char *parity;

/* Read the global config settings */
cfg_fromfile(&c fg, cfgfile);

/* Read the comm port list */
if (cfg_readbuf(cf gfile, "comm_ports ", ports, sizeof(ports)) == NULL)
errend("Couldn' t find 'comm_ports' entry in config file '%s'", cfgfile);

vlist_clear(&pi pes);

/* Parse the comm ports list */
p = strtok(ports, ",");
while (p)
{
if (sscanf(p, "%d", &port) > 0)
{
pipe = malloc(sizeof(p ipe_s));
//pipe_init(pipe) ;
if (pipe == NULL)
perrend("malloc (pipe_s)");

cfg_init(&local , port);

/* Copy global settings to those for current pipe */
cfg_assign(&loc al, &cfg);

/* Set the comm port */
local.ints[CFG_IPORT].val = port;

/* Load this pipe's config */
cfg_fromfile(&l ocal, cfgfile);

/* Try initializing the pipe */
if (pipe_init(pipe , local.ints[CFG_INETPORT].val))
perrend("pipe_i nit");

/* Copy over the rest of the pipe's config */
pipe->timeout = local.ints[CFG_ITIMEOUT].val;
sinfo.port = port;
sinfo.baud = local.ints[CFG_IBAUD].val;
sinfo.stopbits = local.ints[CFG_ISTOP].val;
sinfo.databits = local.ints[CFG_IDATA].val;

parity = local.strs[CFG_SPARITY].val;

if (strcmp(parity, "none") == 0)
{
sinfo.parity = SIO_PARITY_NONE ;
}
else if (strcmp(parity, "even") == 0)
{
sinfo.parity = SIO_PARITY_EVEN ;
}
else if (strcmp(parity, "odd") == 0)
{
sinfo.parity = SIO_PARITY_ODD;
}
else
{
errend("Unknown parity string '%s'", parity);
}

if (sio_setinfo(&p ipe->sio, &sinfo))
errend("Unable to configure comm port %d", port);

/* Finally add the pipe to the pipes list */
vlist_add(&pipe s, pipes.tail, pipe);

cfg_cleanup(&lo cal);
}

p = strtok(NULL, ",");
}

/* Clean up local cfg struct */
cfg_cleanup(&lo cal);

return 0;
}

int waitclients(voi d)
{
int fd_max;
fd_set fds;
vlist_i *it;
pipe_s *pit, *newpipe;
tcpsock_s *newsock;
thr_t thread;

fd_max = 0;
FD_ZERO(&fds);

/* Set all sockets to listen */
for (it = pipes.head; it; it = it->next)
{
pit = (pipe_s *)it->data;

if (tcp_listen(&pi t->sock))
perror("waitcli ents() - tcp_listen()");
}

printf("Serprox y - (C)1999 Stefano Busti - Waiting for clients\n");

while (1)
{
/* Iterate through the pipe list */
for (it = pipes.head; it; it = it->next)
{
pit = (pipe_s *)it->data;

/* Monitor socket fd of each */
FD_SET(pit->sock.fd, &fds);

/* Track max fd */
if (pit->sock.fd > fd_max)
fd_max = pit->sock.fd;
}

/* Wait for a read ( == accept() in this case) */
if (select(fd_max + 1, &fds, NULL, NULL, NULL) == -1)
perrend("waitcl ients() - select()");
/* Find which sockets are involved */
for (it = pipes.head; it; it = it->next)
{
pit = (pipe_s *)it->data;

if (FD_ISSET(pit->sock.fd, &fds))
{
/* Create a new pipe struct for the new thread */
newpipe = malloc(sizeof(p ipe_s));
if (!newpipe)
perrend("waitcl ients() - malloc(pipe_s)" );

newpipe->sio = pit->sio;

/* Try to open serial port */
if (sio_open(&newp ipe->sio))
{
tcp_refuse(&pit->sock);
error("Failed to open comm port - connection refused");
free(newpipe);
continue;
}

/* Accept the connection */
newsock = tcp_accept(&pit->sock);

/* All ok? */
if (newsock)
{
newpipe->sock = *newsock;
free(newsock);

newpipe->timeout = pit->timeout;
newpipe->mutex = pit->mutex;

/* Create the server thread */
if (thr_create(&th read, 1, serve_pipe, newpipe))
{
error("Feck - thread creation failed");
free(newpipe);
}
else
{
fprintf(stderr, "Server thread launched\n");
}
}
else
{
perror("waitcli ents() - accept()");
free(newpipe);
}
}
}
}
return 0;
}

/* Main routine for the server threads */
thr_startfunc_t serve_pipe(void *data)
{
char sio_buf[BUFSIZ], sock_buf[BUFSIZ];
int fd_max, sio_fd, sock_fd;
int sio_count, sock_count;
int res, port;
fd_set rfds, wfds;
pipe_s *pipe = (pipe_s *)data;
#if defined(__UNIX_ _)
struct timeval tv = {pipe->timeout, 0};
struct timeval *ptv = &tv;
#elif defined(__WIN32 __)
struct timeval tv = {0,10000};
struct timeval *ptv = &tv;
DWORD msecs = 0, timeout = pipe->timeout * 1000;
#endif

port = pipe->sio.info.por t;

/* Only proceed if we can lock the mutex */
if (thr_mutex_tryl ock(pipe->mutex))
{
error("server(% d) - resource is locked", port);
}
else
{

sio_count = 0;
sock_count = 0;
sio_fd = pipe->sio.fd;
sock_fd = pipe->sock.fd;
#if defined(__UNIX_ _)
fd_max = sio_fd > sock_fd ? sio_fd : sock_fd;
#elif defined(__WIN32 __)
fd_max = sock_fd;
msecs = GetTickCount();
#endif
fprintf(stderr, "server(%d) - thread started\n", port);

while (1)
{
FD_ZERO(&rfds);
FD_ZERO(&wfds);

#if defined(__UNIX_ _)
/* Always ask for read notification to check for EOF */
FD_SET(sio_fd, &rfds);
/* Only ask for write notification if we have something to write */
if (sock_count > 0)
FD_SET(sio_fd, &wfds);

/* Reset timeout values */
tv.tv_sec = pipe->timeout;
tv.tv_usec = 0;

#endif
/* Always ask for read notification to check for EOF */
FD_SET(sock_fd, &rfds);
/* Only ask for write notification if we have something to write */
if (sio_count > 0)
FD_SET(sock_fd, &wfds);

//DBG_MSG2("serve r(%d) waiting for events", port);

/* Wait for read/write events */
res = select(fd_max + 1, &rfds, &wfds, NULL, ptv);
if (res == -1)
{
perror2("server (%d) - select()", port);
break;
}
#if defined(__UNIX_ _)

/* Use the select result for timeout detection */
if (res == 0)
{
fprintf(stderr, "server(%d) - timed out\n", port);
break;
}

/* Input from serial port? */
if (FD_ISSET(sio_f d, &rfds))
#elif defined(__WIN32 __)

if (1)
#endif
{
/* Only read input if buffer is empty */
if (sio_count == 0)
{
sio_count = sio_read(&pipe->sio, sio_buf, sizeof(sio_buf) );
if (sio_count <= 0)
{
if (sio_count == 0)
{
#if defined(__UNIX_ _)
fprintf(stderr, "server(%d) - EOF from sio\n", port);
break;
#endif
}
else
{
perror2("server (%d) - read(sio)", port);
break;
}
}
else
{
DBG_MSG3("serve r(%d) - read %d bytes from sio", port, sio_count);
}
}
}

/* Write to socket possible? */
if (FD_ISSET(sock_ fd, &wfds))
{
if (sio_count > 0)
{
if ((res = tcp_write(&pipe->sock, sio_buf, sio_count)) < 0)
{
perror2("server (%d) - write(sock)", port);
break;
}
DBG_MSG3("serve r(%d) - Wrote %d bytes to sock", port, res);
sio_count -= res;
}
}
/* Input from socket? */
if (FD_ISSET(sock_ fd, &rfds))
{
/* Only read input if buffer is empty */
if (sock_count == 0)
{
sock_count = tcp_read(&pipe->sock, sock_buf, sizeof(sock_buf ));
if (sock_count <= 0)
{
if (sock_count == 0)
{
fprintf(stderr, "server(%d) - EOF from sock\n", port);
break;
}
else
{
perror2("server (%d) - read(sock)", port);
break;
}
}
DBG_MSG3("serve r(%d) - read %d bytes from sock", port, sock_count);
}
}

#if defined(__UNIX_ _)
/* Write to serial port possible? */
if (FD_ISSET(sio_f d, &wfds))
#elif defined(__WIN32 __)

/* No socket IO performed? */
if ((!FD_ISSET(soc k_fd, &rfds)) && (!FD_ISSET(sock _fd, &wfds)))
{
/* Break on a time out */
if (GetTickCount() - msecs > timeout)
{
fprintf(stderr, "server(%d) - timed out\n", port);
break;
}
}
else
{
msecs = GetTickCount();
}

if (1)
#endif
{
if (sock_count > 0)
{
if ((res = sio_write(&pipe->sio, sock_buf, sock_count)) < 0)
{
perror2("server (%d) - write(sio)", port);
break;
}
DBG_MSG3("serve r(%d) - wrote %d bytes to sio", port, res);
sock_count -= res;
}
}

}

/* Unlock our mutex */
thr_mutex_unloc k(pipe->mutex);
}

fprintf(stderr, "server(%d) exiting\n", port);

/* Clean up - don't call pipe_cleanup() as that would nuke our mutex */
sio_cleanup(&pi pe->sio);
tcp_cleanup(&pi pe->sock);
free(pipe);

thr_exit((thr_e xitcode_t)0);

return (thr_exitcode_t )0;
}

void debug(void)
{
vlist_i *it;
pipe_s *pit;
int i = 1;

fprintf(stderr, "pipes:\n\n ");
vlist_debug(&pi pes, stderr);

for (it = pipes.head; it; it = it->next)
{
pit = (pipe_s *)it->data;

fprintf(stderr, "sio[%d]:\n\n", i);
sio_debug(&pit->sio, stderr);

fprintf(stderr, "sock[%d]:\n\n", i);
tcp_debug(&pit->sock, stderr);

i++;
}
}
--
mcu development team
http://arm.web7days.com

Jul 22 '05 #1
1 2466
OZ wrote:
the serproxy claim itself a multi-thread proxy thing.


This group is for standard C++ language only. The standard C++ does not
contain things that are in your program and therefore your question is
off topic here.

Please don't multipost.

Please read groups faq before posting.
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
430
by: Durai | last post by:
Hello All, How to test the "Multiuser testing" in PostgreSQL?. I used the apache bench "ab" tool for this one. The following command execute the "test.php" 50 times concurrently. $ ab -c 1 -n 50 http://127.0.0.1/test.php The test.php file contains the following contents:
29
3690
by: Mark B | last post by:
We have an Access app (quite big) at www.orbisoft.com/download. We have had requests by potential users to have it converted to an SQL version for them since there corporate policy excludes them from buying mdb backends. Here's the (million dollar?) questions :) How long and how difficult a process would it be? Which SQL platform would we be best to develop it on?
25
4363
by: cory | last post by:
Hi, I have an Access database and am having an ASP.NEt application written for it. It is almost complete. I have a hosting company that I signed up with a month ago but before I did anything I asked them if Access and ASP.NET would work on their servers, they said yes so I bought in. Now they are saying my application wont work on their servers using MSaccess and I can only use SQL or asp 3.0. They are saying Microsoft is trying to...
2
1514
by: Deano | last post by:
One of the more challenging things on my app's wishlist is to make it multi-user on a LAN. For the record my app was always intended to a single-user but things have changed. It's mostly composed of bound forms handling records numbered in the hundreds, sometimes a few thousand. The code of course refers to tables in the local mdb. I allow the user to create external backups of the tables in the database and to restore them. Because...
5
2643
by: OZ | last post by:
the serproxy claim itself a multi-thread proxy thing. I have sent email to write the original writer and there is no replay after 3 weeks. my configuration and setting are good. http://www.lspace.nildram.co.uk/freeware.html I installed it in rh 9.0 I found it is single user only.
3
12928
by: Bill Nicholson | last post by:
What tools are available to convert Access projects (Forms, Code, Queries, Reports) to VB Dot Net? Does anyone have experience with this type of conversion? Please tell me I don't have to do it by hand! Thanks, Bill
1
2338
by: Nethra | last post by:
Hi... I am trying a program which convert the multiline comment type in a program to single line comment type ie. /*have a nice day */ to //have a //nice day
4
4649
by: Peter | last post by:
Does anyone know how to convert the following VB6 code to C# code? Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal bytes As Long) Dim sngArray(0) As Single strString = Chr$(107) & Chr$(62) & Chr(139) & Chr$(65) CopyMemory sngArray(0), ByVal strString, Len(strString) After running the code sngArray(0) = 17.40548
0
2854
by: raamay | last post by:
I am new to VB.Net but since i have a good experience in VB6(having developed 2 to 3 desktop applications), i find no problem coping with the new environment at this stage. Well, i am planning to learn VB.Net and want to kickoff with development of a database application which is multiuser in nature. But as of now, i have not developed multiuser applications even in VB6. Now i want to get some advises before i move ahead. I want to know...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.