当前位置: 技术问答>linux和unix
pthread_create 传参简单问题,大家指教。
来源: 互联网 发布时间:2016-07-20
本文导语: ser.c #include #include #include #include #include #define DEBUG #ifdef DEBUG #define DPRINT(fmt, arg...) printf("FUNCTION %s | LINE %d "fmt"n", __FUNCTION__, __LINE__, ##arg) #else #define DPRINT(fmt, arg...) #endif int newfd[15] = {0}; int recvthread...
ser.c
#include
#include
#include
#include
#include
#define DEBUG
#ifdef DEBUG
#define DPRINT(fmt, arg...) printf("FUNCTION %s | LINE %d "fmt"n", __FUNCTION__, __LINE__, ##arg)
#else
#define DPRINT(fmt, arg...)
#endif
int newfd[15] = {0};
int recvthread(void *number)
{
char buffer[20] = {0};
int rv = 0;
int nu = *((int *)number);
printf("nu is %dn",nu);
while(1)
{
usleep(3000000);
rv = recv(newfd[0],buffer,18, 0);
if(-1 == rv)
printf("recv failed n");
printf("recv buffer is %sn",buffer);
}
}
int main(int argc, char *argv[])
{
int sockfd;
int rv = 0;
int i = 0;
int sin_size = 0;
char buffer[20] = {0};
struct sockaddr_in addr;
struct sockaddr_in addr2;
pthread_t ntid;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd
#include
#include
#include
#include
#include
#define DEBUG
#ifdef DEBUG
#define DPRINT(fmt, arg...) printf("FUNCTION %s | LINE %d "fmt"n", __FUNCTION__, __LINE__, ##arg)
#else
#define DPRINT(fmt, arg...)
#endif
int newfd[15] = {0};
int recvthread(void *number)
{
char buffer[20] = {0};
int rv = 0;
int nu = *((int *)number);
printf("nu is %dn",nu);
while(1)
{
usleep(3000000);
rv = recv(newfd[0],buffer,18, 0);
if(-1 == rv)
printf("recv failed n");
printf("recv buffer is %sn",buffer);
}
}
int main(int argc, char *argv[])
{
int sockfd;
int rv = 0;
int i = 0;
int sin_size = 0;
char buffer[20] = {0};
struct sockaddr_in addr;
struct sockaddr_in addr2;
pthread_t ntid;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd