[asterisk-dev] How to terminate allocated socket resource when channel hangs up!
ast guy
astguy at gmail.com
Tue Nov 24 11:37:38 CST 2009
Hi,
In my asterisk application app_myApplication() code, I have to bind a
socket to a dynamic port number, so that I can send/receive some strings. I
am able to get it working by below code.
Now the problem is; say the read timeout of socket is 60 secs and user hangs
up the channel in 30 seconds, Call is disconnected but still
app_myApplication() remains for that channel and when 60 seconds have
passed. Then normal application follow is executed and channel closes
gracefully.
Is there any way that I can terminate the socket along with channel hangup
event ?
///------------------------------ CODE
-----------------------------------------
int sockfd, new_fd; // listen on sock_fd
struct sockaddr_in my_addr; // my address information
struct sockaddr_in their_addr; // connector's address information
socklen_t sin_size;
struct timeval tv;
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
return -1;
}
my_addr.sin_family = AF_INET; // host byte order
my_addr.sin_port = htons(atoi(port)); // short, network byte order
my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero);
if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof my_addr) == -1) {
return -1;
}
if (listen(sockfd, BACKLOG) == -1) {
return -1;
}
// HERE I am setting the socket Read time out
tv.tv_sec = 60;
tv.tv_usec = 0;
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv) == -1) {
return -1;
}
///------------------------------ CODE
-----------------------------------------
/ag
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20091124/650ee6aa/attachment.htm
More information about the asterisk-dev
mailing list