[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coldsync-hackers] speed



On Fri, 17 Oct 2003, Kevin Velghe wrote:
> I'm trying to write a sync-conduit using C.
> That program gets activated by coldsync without any problems.
> It can read the headers and it gets the command-line arguments. But I
> seem to be stuck when I try to use the SPC-stuff.

	Are you writing a standalone program, or a conduit to be linked
into the 'coldsync' executable?
	If you're writing a new built-in conduit, look for the "dummy"
conduit in src/conduits/ and src/conduit.c .

> Am I right if I'm thinking that I should write my requests to the file
> descriptor I got from the headers...

	Yes.

> And that I must read the results from stdin?

	No, the SPC file descriptor is for two-way communication with
'coldsync'. You read and write the same descriptor.

> And if I'm trying to write to that file descriptor... am I on the right
> track if I'm doing stuff like
>
> typedef enum {
> 	SPCOP_NOP = 0,
> 	SPCOP_DBINFO,
> 	SPCOP_DLPC,
> 	SPCOP_DLPR
> } SPC_Op;
>
> typedef enum {
> 	SPCERR_OK = 0,
> 	SPCERR_BADOP,
> 	SPCERR_NOMEM
> } SPC_Errno;
>
> struct spc_hdr {
> 	unsigned short op;
> 	unsigned short status;
> 	unsigned long len;
> };
>
> int SPCP;   //this contains the handle from SPCPipe...
> struct spc_hdr requestheader;
>
> //filling up the request with a no-op...
> requestheader.op = SPCOP_NOP;
> requestheader.status = SPCERR_BADOP;
> requestheader.len = 0;
>
> write(SPCP, &requestheader, 64);

	I think so, except that
	- When you're sending a request, you don't need to fill in
	  'status'. That will only have a meaningful value in the
	  response.
	  But this allows you to use the same 'struct spc_hdr' for both
	  the request and the response.
	- You're sending 64 bytes, consisting of 'requestheader' (8
	  bytes), plus the 56 bytes after that. If you're lucky, this will
	  cause a segmentation fault and you'll find the problem. If
	  you're unlucky, it'll work, and 'coldsync' will see random
	  garbage and try to interpret it as an SPC request.

> PS : Does anybody know of some tutorial about how to write
> coldsyncconduits in C or C++  posted somewhere on the internet?

	Nope. I think you're the first person to do this.
	If you feel like contributing, then it would be great if you could
contribute a library to make all of this less painful for the next person
who tries this.
	If you don't feel like writing a library, you may want to write a
README.c-conduits file that talks about some of the problems you've run
across, how you solved them, and generally warning people about what
sucks.

-- 
Andrew Arensburger                      Actually, these _do_ represent the
arensb@ooblick.com                      opinions of ooblick.com!
                        Generic Tagline V 6.01
This message was sent through the coldsync-hackers mailing list.  To remove
yourself from this mailing list, send a message to majordomo@thedotin.net
with the words "unsubscribe coldsync-hackers" in the message body.  For more
information on Coldsync, send mail to coldsync-hackers-owner@thedotin.net.