Dear Team,
When CLI command like below is issued would like to save the running configuration
# show servers server name smtp
To achive this used maapi_save_config() API’s.
Noticed while reading of buffer from stream socket it stuck forever.
Below Code snippet is added in action callback of above CLI command
callback_of_show_server ()
{
/* first we need a maapi socket */
if ((msock = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
confd_fatal("Failed to open socket\n");
if (maapi_connect(maapi_socket, (struct sockaddr*)&addr,sizeof (struct sockaddr_in)) < 0)
confd_fatal("Failed to confd_connect() to confd \n");
maapi_set_user_session(msock,usid);
th = maapi_start_trans(msock, dbname, CONFD_READ)) >= 0); //SUCCESS
int id = maapi_save_config(msock, th, MAAPI_CONFIG_XML_PRETTY, "/system");//SUCCESS
//Open another socket ssock confd_stream_connect
if ((ssock = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
{
confd_fatal("Failed to open socket\n");
}
if(confd_stream_connect(ssock, (struct sockaddr*)&paddr, sizeof(struct sockaddr_in), id, 0) == CONFD_OK) //SUCCESS
{
//Some Code
}
f = fopen("filename.xml"); //SUCCESS
//Always num of bytes read always zero ,hence went to infinite loop.Why?
while ((r = read(ssock, buf, sizeof(buf))) > 0) {
if (fwrite(buf, 1, r, f) != r)
confd_fatal("Failed to write output\n");
}
if (r < 0)
confd_fatal("Failed to read from stream socket\n");
OR
bytes_read = recv(ssock, buffer, BUFSIZ - 1, 0); //bytes_read is zero.Why?
while (bytes_read > 0)
{
buffer[bytes_read] = 0; // Null-terminate the buffer
bytes_read = recv(ssock, buffer, BUFSIZ - 1, 0);
}
if(bytes_read == -1)
{
cout<<"read from stream socket failed\n");
}
close(ssock);
if(maapi_save_config_result(msock, id) == CONFD_OK){} //These API are not executed
if(maapi_finish_trans(msock, th) == CONFD_OK){} //These API are not executed
}
Why bytes read from stream socket is always 0 ?
Could you please help.
Thanks in advance