John Doe
9/10/2011 7:25:00 AM
On Fri, 09 Sep 2011 10:46:12 -0700, Ram Prasad wrote:
> I am a perl programmer , need to write a small tcp client in C to pass
> the input to a perl Daemon
> This is going to be a very high volume application , So I better make
> sure the code is efficient enough.
If you want efficiency, see if you can avoid TCP in favour of Unix-domain
sockets. A connection to a Unix-domain socket is just a bidirectional
pipe. A TCP connection, even one via the loopback interface, involves
splitting the data into packets, calculate checksum, routing, firewall,
validate checksum, reassembly.
As for your code: I don't see any reason to copy the data line-by-line;
replacing fgets() with read() may provide some performance gain.
A bigger performance gain could be obtained by eliminating your program
entirely, by having whatever would otherwise write to your program's stdin
talk to the daemon directly.