[Asterisk-Users] C Manager Interface Client

Tressler, Joshua A tressler at purdue.edu
Fri Sep 30 09:51:48 MST 2005


List:
 
This is my first manager client that I've written so please bear with me:
 
I am trying to write a C manager interface client to interface with our CRM software. I am having an issue while reading the data from the manager interface.
 
I am writing this in C and I have the following code:
while(1)
{
 bzero(buffer,sizeof(buffer));
 readCode = read(socketHandle,buffer,sizeof(buffer));
 if(readCode < 0)
 {
  printf("ERROR READING FROM SOCKET\n");
  exit(0);
 }
 printf("%s",buffer);
}

This prints out everything just as connecting to the telnet session would print it out (I do the logging in elsewhere, that isn't the problem here)

This code will read until * has nothing else for me to read from it then print it all out and wait for some more stuff.  Since * seems to print out on 5038 in "blocks" of text read(...) will never cut off in the middle of a block.
However, on one instance, and this is the only one we can reproduce the results on, * puts out Event: ****** then stops, Privilege: ********, then stops and then prints out the rest.  This really screws up my parsing as i normally parse using a tokenizer on \r\n\r\n and pass each block off to a parsing method.  I found this problem using the following code:
while(1)
{
 bzero(buffer,sizeof(buffer));
 readCode = read(socketHandle,buffer,sizeof(buffer));
 if(readCode < 0)
 {
  printf("ERROR READING FROM SOCKET\n");
  exit(0);
 }
 printf("%s\n",buffer);  ////////This is the main difference \n
}
In this case I get output as follows:
...
...
.
.
Event: Hangup
 
Privilege: call,all
 
Channel: SIP/1542200-543f
Uniqueid: 1128041150.26
Cause: 0
Cause-txt: Unknown
...
...
.
.
In this case "Event: Hangup", "Privilege: call, all", and the rest all get passed off to my parser.  Obviously a problem.

Is * spitting this data out to me in three seperate chunks or is my socket not blocking correctly?

Any suggestions as to why this would happen?
 
TIA,
 
Joshua
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20050930/ca099944/attachment.htm


More information about the asterisk-users mailing list