Mercurial > mplayer.hg
comparison input/input.c @ 9836:8016c8455f1d
allow select()less compilation
author | faust3 |
---|---|
date | Fri, 04 Apr 2003 20:56:29 +0000 |
parents | 1e761763566c |
children | 150d1ef4204d |
comparison
equal
deleted
inserted
replaced
9835:0bd390e01057 | 9836:8016c8455f1d |
---|---|
782 return ret; | 782 return ret; |
783 } | 783 } |
784 | 784 |
785 int | 785 int |
786 mp_input_read_key_code(int time) { | 786 mp_input_read_key_code(int time) { |
787 #ifndef HAVE_NO_POSIX_SELECT | |
787 fd_set fds; | 788 fd_set fds; |
788 struct timeval tv,*time_val; | 789 struct timeval tv,*time_val; |
790 #endif | |
789 int i,n=0,max_fd = 0; | 791 int i,n=0,max_fd = 0; |
790 static int last_loop = 0; | 792 static int last_loop = 0; |
791 | 793 |
792 if(num_key_fd == 0) | 794 if(num_key_fd == 0) |
793 return MP_INPUT_NOTHING; | 795 return MP_INPUT_NOTHING; |
794 | 796 |
797 #ifndef HAVE_NO_POSIX_SELECT | |
795 FD_ZERO(&fds); | 798 FD_ZERO(&fds); |
799 #endif | |
796 // Remove fd marked as dead and build the fd_set | 800 // Remove fd marked as dead and build the fd_set |
797 // n == number of fd's to be select() checked | 801 // n == number of fd's to be select() checked |
798 for(i = 0; (unsigned int)i < num_key_fd; i++) { | 802 for(i = 0; (unsigned int)i < num_key_fd; i++) { |
799 if( (key_fds[i].flags & MP_FD_DEAD) ) { | 803 if( (key_fds[i].flags & MP_FD_DEAD) ) { |
800 mp_input_rm_key_fd(key_fds[i].fd); | 804 mp_input_rm_key_fd(key_fds[i].fd); |
802 continue; | 806 continue; |
803 } else if(key_fds[i].flags & MP_FD_NO_SELECT) | 807 } else if(key_fds[i].flags & MP_FD_NO_SELECT) |
804 continue; | 808 continue; |
805 if(key_fds[i].fd > max_fd) | 809 if(key_fds[i].fd > max_fd) |
806 max_fd = key_fds[i].fd; | 810 max_fd = key_fds[i].fd; |
811 #ifndef HAVE_NO_POSIX_SELECT | |
807 FD_SET(key_fds[i].fd,&fds); | 812 FD_SET(key_fds[i].fd,&fds); |
813 #endif | |
808 n++; | 814 n++; |
809 } | 815 } |
810 | 816 |
811 if(num_key_fd == 0) | 817 if(num_key_fd == 0) |
812 return MP_INPUT_NOTHING; | 818 return MP_INPUT_NOTHING; |
813 | 819 |
820 #ifndef HAVE_NO_POSIX_SELECT | |
814 // if we have fd's without MP_FD_NO_SELECT flag, call select(): | 821 // if we have fd's without MP_FD_NO_SELECT flag, call select(): |
815 if(n>0){ | 822 if(n>0){ |
816 | 823 |
817 if(time >= 0 ) { | 824 if(time >= 0 ) { |
818 tv.tv_sec=time/1000; | 825 tv.tv_sec=time/1000; |
829 } | 836 } |
830 break; | 837 break; |
831 } | 838 } |
832 | 839 |
833 } | 840 } |
841 #endif | |
834 | 842 |
835 for(i = last_loop + 1 ; i != last_loop ; i++) { | 843 for(i = last_loop + 1 ; i != last_loop ; i++) { |
836 int code = -1; | 844 int code = -1; |
837 // This is to check all fd in turn | 845 // This is to check all fd in turn |
838 if((unsigned int)i >= num_key_fd) { | 846 if((unsigned int)i >= num_key_fd) { |
839 i = -1; | 847 i = -1; |
840 last_loop++; | 848 last_loop++; |
841 last_loop %= (num_key_fd+1); | 849 last_loop %= (num_key_fd+1); |
842 continue; | 850 continue; |
843 } | 851 } |
852 #ifndef HAVE_NO_POSIX_SELECT | |
844 // No input from this fd | 853 // No input from this fd |
845 if(! (key_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(key_fds[i].fd,&fds)) | 854 if(! (key_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(key_fds[i].fd,&fds)) |
846 continue; | 855 continue; |
856 #endif | |
847 if(key_fds[i].fd == 0) { // stdin is handled by getch2 | 857 if(key_fds[i].fd == 0) { // stdin is handled by getch2 |
848 code = getch2(time); | 858 code = getch2(time); |
849 if(code < 0) | 859 if(code < 0) |
850 code = MP_INPUT_NOTHING; | 860 code = MP_INPUT_NOTHING; |
851 } | 861 } |
957 return NULL; | 967 return NULL; |
958 } | 968 } |
959 | 969 |
960 static mp_cmd_t* | 970 static mp_cmd_t* |
961 mp_input_read_cmds(int time) { | 971 mp_input_read_cmds(int time) { |
972 #ifndef HAVE_NO_POSIX_SELECT | |
962 fd_set fds; | 973 fd_set fds; |
963 struct timeval tv,*time_val; | 974 struct timeval tv,*time_val; |
975 #endif | |
964 int i,n = 0,max_fd = 0,got_cmd = 0; | 976 int i,n = 0,max_fd = 0,got_cmd = 0; |
965 mp_cmd_t* ret; | 977 mp_cmd_t* ret; |
966 static int last_loop = 0; | 978 static int last_loop = 0; |
967 | 979 |
968 if(num_cmd_fd == 0) | 980 if(num_cmd_fd == 0) |
969 return NULL; | 981 return NULL; |
970 | 982 |
983 #ifndef HAVE_NO_POSIX_SELECT | |
971 FD_ZERO(&fds); | 984 FD_ZERO(&fds); |
985 #endif | |
972 for(i = 0; (unsigned int)i < num_cmd_fd ; i++) { | 986 for(i = 0; (unsigned int)i < num_cmd_fd ; i++) { |
973 if( (cmd_fds[i].flags & MP_FD_DEAD) || (cmd_fds[i].flags & MP_FD_EOF) ) { | 987 if( (cmd_fds[i].flags & MP_FD_DEAD) || (cmd_fds[i].flags & MP_FD_EOF) ) { |
974 mp_input_rm_cmd_fd(cmd_fds[i].fd); | 988 mp_input_rm_cmd_fd(cmd_fds[i].fd); |
975 i--; | 989 i--; |
976 continue; | 990 continue; |
978 continue; | 992 continue; |
979 if(cmd_fds[i].flags & MP_FD_GOT_CMD) | 993 if(cmd_fds[i].flags & MP_FD_GOT_CMD) |
980 got_cmd = 1; | 994 got_cmd = 1; |
981 if(cmd_fds[i].fd > max_fd) | 995 if(cmd_fds[i].fd > max_fd) |
982 max_fd = cmd_fds[i].fd; | 996 max_fd = cmd_fds[i].fd; |
997 #ifndef HAVE_NO_POSIX_SELECT | |
983 FD_SET(cmd_fds[i].fd,&fds); | 998 FD_SET(cmd_fds[i].fd,&fds); |
999 #endif | |
984 n++; | 1000 n++; |
985 } | 1001 } |
986 | 1002 |
987 if(num_cmd_fd == 0) | 1003 if(num_cmd_fd == 0) |
988 return NULL; | 1004 return NULL; |
989 | 1005 |
1006 #ifndef HAVE_NO_POSIX_SELECT | |
990 if(time >= 0) { | 1007 if(time >= 0) { |
991 tv.tv_sec=time/1000; | 1008 tv.tv_sec=time/1000; |
992 tv.tv_usec = (time%1000)*1000; | 1009 tv.tv_usec = (time%1000)*1000; |
993 time_val = &tv; | 1010 time_val = &tv; |
994 } else | 1011 } else |
1004 if(!got_cmd) | 1021 if(!got_cmd) |
1005 return NULL; | 1022 return NULL; |
1006 } | 1023 } |
1007 break; | 1024 break; |
1008 } | 1025 } |
1026 #endif | |
1009 | 1027 |
1010 for(i = last_loop + 1; i != last_loop ; i++) { | 1028 for(i = last_loop + 1; i != last_loop ; i++) { |
1011 int r = 0; | 1029 int r = 0; |
1012 char* cmd; | 1030 char* cmd; |
1013 if((unsigned int)i >= num_cmd_fd) { | 1031 if((unsigned int)i >= num_cmd_fd) { |
1014 i = -1; | 1032 i = -1; |
1015 last_loop++; | 1033 last_loop++; |
1016 last_loop %= (num_cmd_fd+1); | 1034 last_loop %= (num_cmd_fd+1); |
1017 continue; | 1035 continue; |
1018 } | 1036 } |
1037 #ifndef HAVE_NO_POSIX_SELECT | |
1019 if( ! (cmd_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(cmd_fds[i].fd,&fds) && ! (cmd_fds[i].flags & MP_FD_GOT_CMD) ) | 1038 if( ! (cmd_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(cmd_fds[i].fd,&fds) && ! (cmd_fds[i].flags & MP_FD_GOT_CMD) ) |
1020 continue; | 1039 continue; |
1040 #endif | |
1021 | 1041 |
1022 r = mp_input_read_cmd(&cmd_fds[i],&cmd); | 1042 r = mp_input_read_cmd(&cmd_fds[i],&cmd); |
1023 if(r < 0) { | 1043 if(r < 0) { |
1024 if(r == MP_INPUT_ERROR) | 1044 if(r == MP_INPUT_ERROR) |
1025 mp_msg(MSGT_INPUT,MSGL_ERR,"Error on cmd fd %d\n",cmd_fds[i].fd); | 1045 mp_msg(MSGT_INPUT,MSGL_ERR,"Error on cmd fd %d\n",cmd_fds[i].fd); |