-
Notifications
You must be signed in to change notification settings - Fork 942
Description
Hi:
I use F-stack to create a large number of clients, ff_bind port, and hang up.
This is my code:
#include <stdio.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
#include <assert.h>
#include<linux/netfilter_ipv4.h>
#include "ff_config.h"
#include "ff_api.h"
#include "ff_epoll.h"
#include <sys/time.h>
#include <netinet/tcp.h>
void server_connect()
{
int serverfd = ff_socket(AF_INET, SOCK_STREAM, 0);
if (serverfd < 0 ) {
printf("ff_socket failed\n");
exit(0);
}
struct sockaddr_in server;
bzero(&server, sizeof(server));
server.sin_family = AF_INET;
server.sin_port = htons(5432);
server.sin_addr.s_addr = inet_addr("192.168.60.202");
int on = 1;
ff_ioctl(serverfd, FIONBIO, &on);
struct sockaddr_in local;
bzero(&local, sizeof(local));
local.sin_family = AF_INET;
local.sin_port = htons(INADDR_ANY);
uint32_t local_ip = inet_addr("192.168.60.201");
local.sin_addr.s_addr = local_ip;
int ret = ff_bind(serverfd, (struct linux_sockaddr *)&local, sizeof(local));
if (ret < 0) {
printf("pid:%d ff_bind failed :%d\n",getpid(),ntohs(local.sin_port));
exit(1);
}
ff_connect(serverfd, (const struct linux_sockaddr *)&server, sizeof(struct sockaddr_in));
}
int index = 0;
int loop(void *arg)
{
index++;
if(index < 100){
usleep(100000);
return 0;
}
if(index > 20000)return 0;
server_connect();
usleep(1000);
}
int main(int argc, char * argv[])
{
ff_init(argc, argv);
ff_run(loop, NULL);
return 0;
}
I use pstack to view the stack

Hundreds of connections can be built, and they hang up.The problem is ff_bind. Can you modify it?
