Client server pair to get efficient realtime
claws-mail receive calls by use of procmail
2008-06-29 y0shi claws_daemon.c
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
int main() {
int32_t i,boolean = 0;
int32_t sfd = socket(PF_INET, SOCK_STREAM, 0);
if(-1 == sfd) {
printf("can not create socket\n");
exit(-1);
}
struct sockaddr_in stSockAddr;
bzero(&stSockAddr, sizeof(stSockAddr));
stSockAddr.sin_family = AF_INET;
stSockAddr.sin_port = htons(9333);
stSockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
if(-1 == bind(sfd,(struct sockaddr*) &stSockAddr, sizeof(stSockAddr))) {
printf("error bind failed\n");
exit(-1);
}
if(-1 == listen(sfd, 10)) {
printf("error listen failed\n");
exit(-1);
}
for(; ;) {
int32_t cfd = accept(sfd, NULL, NULL);
if(0 > cfd) {
printf("error accept failed\n");
exit(-1);
}
recv(cfd, &i, sizeof(i), 0);
boolean = ntohl(i);
if (boolean==1)
system("/usr/bin/claws-mail --receive");
shutdown(cfd, 2);
close(cfd);
}
return 0;
}
2008-06-29 y0shi send2socket.c
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int32_t boolean;
int32_t sfd = socket(PF_INET, SOCK_STREAM, 0);
if (-1 == sfd) {
printf("cannot create socket\n");
exit(-1);
}
struct sockaddr_in stSockAddr;
bzero(&stSockAddr, sizeof(stSockAddr));
printf("%s\n", argv[1]);
stSockAddr.sin_family = AF_INET;
stSockAddr.sin_port = htons(9333);
int32_t i32Res = inet_pton(AF_INET, argv[1],
(void *) &stSockAddr.sin_addr);
if (0 > i32Res) {
printf("error: first parameter is not a valid address family\n");
exit(-1);
}
else if (0 == i32Res) {
printf("char string: second parameter does not contain valid ipaddress\n");
exit(-1);
}
if (-1 == connect(sfd,(struct sockaddr*) &stSockAddr, sizeof(stSockAddr))) {
printf("connect failed\n");
exit(-1);
}
boolean = htonl(1);
send (sfd, &boolean, sizeof(boolean), 0);
shutdown(sfd, 2);
close(sfd);
return 0;
}