Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #427
| From | Joe Beanfish <joe@nospam.duh> |
|---|---|
| Newsgroups | comp.os.linux.development.apps |
| Subject | Re: object file memory |
| Date | 2012-02-09 11:15 -0500 |
| Organization | Thunderstone Software |
| Message-ID | <jh0rfd$u3s@news.thunderstone.com> (permalink) |
| References | (1 earlier) <20120207000059.76@kylheku.com> <jgrc5t$5f0$1@dont-email.me> <jgrmj8$6pc$1@dont-email.me> <alpine.DEB.2.00.1202072202080.25401@login01.caesar.elte.hu> <jgs7dk$ng5$1@dont-email.me> |
On 02/07/2012 05:08 PM, Bill M wrote:
> Ersek, Laszlo wrote, On 2/7/2012 3:09 PM:
>> On Tue, 7 Feb 2012, Bill M wrote:
>>
>>> I have a global declared as follows:
>>>
>>> __thread OCX_COMM_STATE comm_state = OCX_COMM_START;
>>
...
>
> Anyway, I see what my problem is: My main program is actually starting 2
> threads: the 1st is a client loop (a TCP client), and the 2nd is my failed
> attempt to interface to it. So, in the client loop thread I have one
> comm_state, and in the interface thread there is another; and of course they
> have no idea about one another. I need to restructure this program and
> design a better interface.
>
> I'm trying to encapsulate all of the TCP client interaction in one object
> file, and then link that into various other applications that want to use
> this client to talk to the server. I'm not a very good programmer, so it's
> going to take me a couple of tries to make something that is robust.
Then forget the whole idea of using globals. Use a structure to contain
all the "global" info the functions need. Then add open and close functions
to allocate,initialize,and destroy that structure. Pass that structure
to all all related functions.
struct foo_client {
char foo_char;
int foo_int;
SERVER server;
};
struct foo_client *fooclientopen(SERVER server)
{
struct foo_client *p;
p=calloc(1,sizeof(foo_client));
p->foo_char='a';
p->foo_int=0;
p->server=server;
}
struct foo_client *fooclientclose(struct foo_client *p)
{
close p->server;
free(p);
}
int client_write(struct foo_client *p, char* buffer)
{
...
}
Error checking left to you...
Back to comp.os.linux.development.apps | Previous | Next — Previous in thread | Find similar
object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-06 16:41 -0600
Re: object file memory Kaz Kylheku <kaz@kylheku.com> - 2012-02-06 23:07 +0000
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 08:23 -0600
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 08:40 -0600
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 08:58 -0600
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 11:21 -0600
Re: object file memory "Ersek, Laszlo" <lacos@caesar.elte.hu> - 2012-02-07 22:09 +0100
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-07 16:08 -0600
Re: object file memory Bill M <wpmccormick@just_about_everywhere.com> - 2012-02-08 20:42 -0600
Re: object file memory Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-02-09 19:00 +0000
Re: object file memory Joe Beanfish <joe@nospam.duh> - 2012-02-09 11:15 -0500
csiph-web