BurstFS_Server/burstfs_sock.c
int sock_wait_cli_cmd() {
	int rc, i;

	sock_reset();
	rc = poll(poll_set, num_fds, -1);
	if (rc <= 0) {
		return ULFS_ERROR_TIMEOUT;
	}
	else {
			for (i = 0; i < num_fds; i++) {
				if (poll_set[i].fd != -1 && poll_set[i].revents != 0) {
					if (i == 0 && poll_set[i].revents == POLLIN) {
	                    int client_len = sizeof(struct sockaddr_un);

	                    struct sockaddr_un client_address;
	                    int client_sockfd = accept(server_sockfd, \
	                    		(struct sockaddr *)&client_address,\
									(socklen_t *)&client_len);
	                    rc = sock_add(client_sockfd);
	                    if (rc < 0) {
	                    	return ULFS_SOCKETFD_EXCEED;
	                    } else {
	                    	cur_sock_id = i;
	                    	return ULFS_SUCCESS;
	                    }
					} else
						if(i != 0 && poll_set[i].revents == POLLIN) {
							int bytes_read = read(poll_set[i].fd,\
									cmd_buf[i], GEN_STR_LEN);
							if (bytes_read == 0) {
								sock_remove(i);
								detached_sock_id = i;
								return ULFS_SOCK_DISCONNECT;
							}
							cur_sock_id = i;
							return ULFS_SUCCESS;
						} else {
							if (i == 0) {
								return ULFS_SOCK_LISTEN;
							} else {
								detached_sock_id = i;
								if (i != 0 && poll_set[i].revents == POLLHUP) {
									sock_remove(i);
									return ULFS_SOCK_DISCONNECT;
								} else {
									sock_remove(i);
									return ULFS_SOCK_OTHER;

								}
							}
						}
					}
				}
	}

	return ULFS_SUCCESS;

}
/*
 * wait for the client-side command
 * */
wait for the client-side command
wait for the client - side command
int sock_wait_cli_cmd() {
	int rc, i;
	sock_reset();
	rc = poll(poll_set, num_fds, -1);
	if (rc <= 0) {
		return ULFS_ERROR_TIMEOUT;
	}
	else {
			for (i = 0; i < num_fds; i++) {
				if (poll_set[i].fd != -1 && poll_set[i].revents != 0) {
					if (i == 0 && poll_set[i].revents == POLLIN) {
	                    int client_len = sizeof(struct sockaddr_un);
	                    struct sockaddr_un client_address;
	                    int client_sockfd = accept(server_sockfd, \
	                    		(struct sockaddr *)&client_address,\
									(socklen_t *)&client_len);
	                    rc = sock_add(client_sockfd);
	                    if (rc < 0) {
	                    	return ULFS_SOCKETFD_EXCEED;
	                    } else {
	                    	cur_sock_id = i;
	                    	return ULFS_SUCCESS;
	                    }
					} else
						if(i != 0 && poll_set[i].revents == POLLIN) {
							int bytes_read = read(poll_set[i].fd,\
									cmd_buf[i], GEN_STR_LEN);
							if (bytes_read == 0) {
								sock_remove(i);
								detached_sock_id = i;
								return ULFS_SOCK_DISCONNECT;
							}
							cur_sock_id = i;
							return ULFS_SUCCESS;
						} else {
							if (i == 0) {
								return ULFS_SOCK_LISTEN;
							} else {
								detached_sock_id = i;
								if (i != 0 && poll_set[i].revents == POLLHUP) {
									sock_remove(i);
									return ULFS_SOCK_DISCONNECT;
								} else {
									sock_remove(i);
									return ULFS_SOCK_OTHER;
								}
							}
						}
					}
				}
	}
	return ULFS_SUCCESS;
}
int sock_wait_cli_cmd ( ) { int rc , i ; sock_reset ( ) ; rc = poll ( poll_set , num_fds , -1 ) ; if ( rc <= 0 ) { return ULFS_ERROR_TIMEOUT ; } else { for ( i = 0 ; i < num_fds ; i ++ ) { if ( poll_set [ i ] . fd != -1 && poll_set [ i ] . revents != 0 ) { if ( i == 0 && poll_set [ i ] . revents == POLLIN ) { int client_len = sizeof ( struct sockaddr_un ) ; struct sockaddr_un client_address ; int client_sockfd = accept ( server_sockfd , ( struct sockaddr * ) & client_address , ( socklen_t * ) & client_len ) ; rc = sock_add ( client_sockfd ) ; if ( rc < 0 ) { return ULFS_SOCKETFD_EXCEED ; } else { cur_sock_id = i ; return ULFS_SUCCESS ; } } else if ( i != 0 && poll_set [ i ] . revents == POLLIN ) { int bytes_read = read ( poll_set [ i ] . fd , cmd_buf [ i ] , GEN_STR_LEN ) ; if ( bytes_read == 0 ) { sock_remove ( i ) ; detached_sock_id = i ; return ULFS_SOCK_DISCONNECT ; } cur_sock_id = i ; return ULFS_SUCCESS ; } else { if ( i == 0 ) { return ULFS_SOCK_LISTEN ; } else { detached_sock_id = i ; if ( i != 0 && poll_set [ i ] . revents == POLLHUP ) { sock_remove ( i ) ; return ULFS_SOCK_DISCONNECT ; } else { sock_remove ( i ) ; return ULFS_SOCK_OTHER ; } } } } } } return ULFS_SUCCESS ; }
wait for the client-side command
wait for the client - side command