user-0 提问: 关于open or creat创建新文件时返回描述符为0的问题

回复:
user: user-1
content: 读open和creat的man page，检查返回值。

user: user-0
content: 引用 4 楼 user-1 的回复:读open和creat的man page，检查返回值。   SSL_set_connect_state(ssl);     if(!SSL_set_fd(ssl, sockfd))     {         perror("ssl_set_fd failed");         exit(0);     }           printf("ssl_new scuess\n");     if (SSL_connect(ssl) == -1) 这几个函数会有影响么，貌似是调用他们之后才那样的，，昨晚上又莫名其妙的好了，在调试的时候，，

user: user-0
content: 要沉了，，，，怎么破呢  谁给指点指点方法也好

user: user-0
content: 比较乱，，，谢谢拉 有朋友之前碰到过，可自己不是他那种情况，链接如下 http://alwaysgo.blog.hexun.com/16801141_d.html

user: user-0
content: int main(int argc, char *argv[]) { 	SSL *ssl = NULL; 	welecome(); 	if((ssl = connect_server(ssl, argc, argv)) == NULL) 	{ 		printf("server not launch\n"); 		return -1; 	} 	login(ssl); 	while(1) 	{	 		int	choice = 0; 		print_main_menu(); //		setbuf(stdin, NULL); 		scanf("%d", &choice); //		setbuf(stdin, NULL); 		switch(choice) 		{ 			case 1: 				uploadfile(ssl); 				break; 			case 2: 				downloadfile(ssl); 			   	break; 			case 3: 				list_file(ssl); 				break; 			case 4: 				process_server_cmd(ssl); 				break; 			case 5: 				process_local_cmd(); 			default: 				break; 		} 	} 	return 0; } struct package pack(unsigned char cmd, unsigned char state, UFC *pufc,  int count, char *buf) { 	struct package tpackage; 	memset(&tpackage, 0, sizeof(struct package)); 	tpackage.cmd = cmd; 	tpackage.state = state; 	if(buf != NULL) 		memcpy(tpackage.buf, buf, count); 	if(pufc == NULL) 		return tpackage; 	switch(tpackage.cmd) 	{ 	case CMD_LOGIN:	 		strcpy(tpackage.ufc.user, pufc->user); 		break; 	case CMD_DOWN: 		strcpy(tpackage.ufc.filename, pufc->filename); 		break; 	case CMD_UP: 		strcpy(tpackage.ufc.filename, pufc->filename); 		break; 	case CMD_LIST: 		break; 	case CMD_QUIT: 		break; 	case CMD_CMD:  		break; 	default: 		break; 	} 	return tpackage; };  void print_main_menu() { 	printf("   \033[34m------------------------------\033[31mClient  console\033[34m-----------------------------\033[0m\n"); 	printf("   \033[34m|\033[0m                1.Update Files   2.Download Files  3.List File               \033[34m|\033[0m\n"); 	printf("   \033[34m--------------   \033[36mUse \033[31mls \033[36mor \033[31mcd \033[36mto \033[31mdisplayer \033[36mand \033[31mchange dir   \033[34m--------------\033[0m\n"); 	printf("  Please input the Client command:");	 } void welecome() { 	printf("   \033[34m------------------------------\033[31mWelcome to bungarus \033[34m-----------------------------\033[0m\n"); 	printf("   \033[34m|\033[0m               this is a client console of transmit            \033[34m|\033[0m\n"); 	printf("  It is connecting to server....\n");	 } SSL* connect_server(SSL *ssl,int argc, char *argv[]) { 	int i,count=0; 	char ip[32] = "127.0.0.1"; 	if(argc==2) 	{ 		printf("usage error:  ./client 192.168.0.6\n"); //		exit(0); 		strcpy(ip, argv[1]);  		 	}  	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 	int sockfd; 	if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1) 	{ 		perror("socket");	 		exit(0); 	} 	struct sockaddr_in sockaddr; 	memset(&sockaddr,0,sizeof(struct sockaddr_in)); 	sockaddr.sin_family = AF_INET; 	sockaddr.sin_addr.s_addr = inet_addr(ip); 	sockaddr.sin_port = htons(CLIENT_PORT);  	 	if(connect(sockfd,(struct sockaddr* )&sockaddr,sizeof(struct sockaddr_in))==-1) 	{ 		perror("connect"); 		exit(0); 	} 	  SSL_library_init(); 	  OpenSSL_add_all_algorithms(); 	  SSL_load_error_strings(); 	  ctx = SSL_CTX_new(SSLv23_client_method()); 	  if (ctx == NULL) 	  { 	    ERR_print_errors_fp(stdout); 	    exit(1); 	  } 	if((ssl = SSL_new(ctx)) == NULL) 	{ 		perror("ssl_new fail"); 		exit(0); 	} 	SSL_set_connect_state(ssl);     if(!SSL_set_fd(ssl, sockfd)) 	{ 		perror("ssl_set_fd failed"); 		exit(0); 	} 	 	printf("ssl_new scuess\n");     if (SSL_connect(ssl) == -1) 		ERR_print_errors_fp(stderr);   else   { 	printf("Connected with %s encryption\n", SSL_get_cipher(ssl)); 	ShowCerts(ssl);   } 	printf(" connect server scuess\n");   return ssl; 		 } void ShowCerts(SSL * ssl) {   X509 *cert;   char *line;    cert = SSL_get_peer_certificate(ssl);   if (cert != NULL) {     printf("Digital certificate information:\n");     line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);     printf("Certificate: %s\n", line);     free(line);     line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);     printf("Issuer: %s\n", line);     free(line);     X509_free(cert);   }   else     printf("No certificate information£¡\n"); }