Hi,
Try this version of store.c
Error diagnostic for UdmStoreOpen function added.
Please feedback any error messages produced.
Aiko wrote:
> Author: Aiko
> Email: [EMAIL PROTECTED]
> Message:
> Hi,
>
> no firewall. The cachelogd run correct!
>
> cu
> Aiko
>
> Reply: <http://www.mnogosearch.org/board/message.php?id=3541>
--
Maxim Zakharov http://sochi.net.ru/~maxime/
Sochi, Russia http://www.sochi.com/
#include <udm_config.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_WINSOCK_H
#include <winsock.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#include "udm_store.h"
#include "udm_services.h"
#include "udm_xmalloc.h"
#ifdef HAVE_ZLIB
#ifndef MSG_WAITALL
#define MSG_WAITALL 0
#endif
ssize_t UdmRecvall(int s, void *buf, size_t len, int flags) {
size_t received = 0, r;
char *b = buf;
while ( (received < len) && ((r = recv(s, &b[received], len - received, flags)) >= 0
) ) {
received += r;
}
return received;
}
#endif
__INDLIB__ int UdmStoreDoc(UDM_ENV *Conf, const char *Doc, size_t DocSize, unsigned
int rec_id) {
#ifdef HAVE_ZLIB
const char *hello = "S\0";
char result[8];
int s;
if ((s = UdmStoreOpen(Conf)) < 0) {
return -1;
}
send (s, hello, 1, 0);
send (s, &rec_id, sizeof(rec_id), 0);
send (s, &DocSize, sizeof(DocSize), 0);
send (s, Doc, DocSize, 0);
if (UdmRecvall(s, result, 6, MSG_WAITALL) < 0) {
closesocket(s);
return -1;
}
closesocket(s);
if (strncmp(result, "STORED", 6) != 0) {
return -1;
}
return 0;
#else
return -1;
#endif
}
__INDLIB__ char * UdmUnStoreDoc(UDM_ENV *Conf, unsigned int rec_id, size_t *DS) {
#ifdef HAVE_ZLIB
const char *hello = "G\0";
size_t DocSize;
char *Doc = NULL;
int s;
if ((s = UdmStoreOpen(Conf)) < 0) {
return NULL;
}
send (s, hello, 1, 0);
send (s, &rec_id, sizeof(rec_id), 0);
if (UdmRecvall(s, &DocSize, sizeof(DocSize), MSG_WAITALL) < 0) {
closesocket(s);
return NULL;
}
if (DocSize == 0) {
closesocket(s);
return NULL;
}
if ((Doc = UdmXmalloc(DocSize)) == NULL) {
closesocket(s);
return NULL;
}
if (UdmRecvall(s, Doc, DocSize, MSG_WAITALL) < 0) {
closesocket(s);
return NULL;
}
closesocket(s);
*DS = DocSize;
return Doc;
#else
return NULL;
#endif
}
int UdmStoreOpen(UDM_ENV *Conf) {
#ifdef HAVE_ZLIB
struct hostent *hp;
struct sockaddr_in server_addr;
int s, nport = UDM_STORED_PORT;
if(Conf->stored_addr){
char * cport;
if((cport=strchr(Conf->stored_addr,':'))){
*cport='\0';
nport=atoi(cport+1);
}
}else{
return -1;
/* server_addr.sin_addr.s_addr = htonl(INADDR_ANY);*/
}
if ((hp = gethostbyname(Conf->stored_addr)) == 0 ) {
fprintf(stderr, "StoreOpen ERR gethostbyname: %s\n", hstrerror(h_errno));
return -1;
}
bzero(&server_addr, sizeof(server_addr));
memmove(hp->h_addr, &server_addr.sin_addr, (size_t)hp->h_length);
server_addr.sin_family = hp->h_addrtype;
server_addr.sin_port = htons((u_short)nport);
if((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
fprintf(stderr, "StoreOpen ERR socket: %s\n", strerror(errno));
return -1;
}
if(connect(s, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) {
fprintf(stderr, "StoreOpen ERR connect: %s\n", strerror(errno));
closesocket(s);
return -1;
}
return s;
#else
return -1;
#endif
}