diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-23 16:03:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-23 16:03:54 +0000 |
commit | 48f8bbc215fc84a295993fb5bc529a9fe9b11b7e (patch) | |
tree | 1bdaede9381fe465fec7e7149d35a562a0fa7dc8 /src/util/mq.c | |
parent | 4eecf868f0ed39d472884cf6b415bb3b3460dee7 (diff) | |
download | gnunet-48f8bbc215fc84a295993fb5bc529a9fe9b11b7e.tar.gz gnunet-48f8bbc215fc84a295993fb5bc529a9fe9b11b7e.zip |
move to new client API: remove old client API
Diffstat (limited to 'src/util/mq.c')
-rw-r--r-- | src/util/mq.c | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/src/util/mq.c b/src/util/mq.c index ba947d5b8..193823c93 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -220,34 +220,6 @@ struct ServerClientSocketState | |||
220 | 220 | ||
221 | 221 | ||
222 | /** | 222 | /** |
223 | * Implementation-specific state for connection to | ||
224 | * service (MQ for clients). | ||
225 | */ | ||
226 | struct ClientConnectionState | ||
227 | { | ||
228 | /** | ||
229 | * Did we call receive alread alreadyy? | ||
230 | */ | ||
231 | int receive_active; | ||
232 | |||
233 | /** | ||
234 | * Do we also want to receive? | ||
235 | */ | ||
236 | int receive_requested; | ||
237 | |||
238 | /** | ||
239 | * Connection to the service. | ||
240 | */ | ||
241 | struct GNUNET_CLIENT_Connection *connection; | ||
242 | |||
243 | /** | ||
244 | * Active transmission request (or NULL). | ||
245 | */ | ||
246 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
247 | }; | ||
248 | |||
249 | |||
250 | /** | ||
251 | * Call the message message handler that was registered | 223 | * Call the message message handler that was registered |
252 | * for the type of the given message in the given message queue. | 224 | * for the type of the given message in the given message queue. |
253 | * | 225 | * |
@@ -775,175 +747,6 @@ GNUNET_MQ_queue_for_server_client (struct GNUNET_SERVER_Client *client) | |||
775 | 747 | ||
776 | 748 | ||
777 | /** | 749 | /** |
778 | * Type of a function to call when we receive a message | ||
779 | * from the service. | ||
780 | * | ||
781 | * @param cls closure | ||
782 | * @param msg message received, NULL on timeout or fatal error | ||
783 | */ | ||
784 | static void | ||
785 | handle_client_message (void *cls, | ||
786 | const struct GNUNET_MessageHeader *msg) | ||
787 | { | ||
788 | struct GNUNET_MQ_Handle *mq = cls; | ||
789 | struct ClientConnectionState *state; | ||
790 | |||
791 | state = mq->impl_state; | ||
792 | if (NULL == msg) | ||
793 | { | ||
794 | GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ); | ||
795 | return; | ||
796 | } | ||
797 | GNUNET_CLIENT_receive (state->connection, | ||
798 | &handle_client_message, | ||
799 | mq, | ||
800 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
801 | GNUNET_MQ_inject_message (mq, msg); | ||
802 | } | ||
803 | |||
804 | |||
805 | /** | ||
806 | * Transmit a queued message to the session's client. | ||
807 | * | ||
808 | * @param cls consensus session | ||
809 | * @param size number of bytes available in @a buf | ||
810 | * @param buf where the callee should write the message | ||
811 | * @return number of bytes written to buf | ||
812 | */ | ||
813 | static size_t | ||
814 | connection_client_transmit_queued (void *cls, | ||
815 | size_t size, | ||
816 | void *buf) | ||
817 | { | ||
818 | struct GNUNET_MQ_Handle *mq = cls; | ||
819 | const struct GNUNET_MessageHeader *msg; | ||
820 | struct ClientConnectionState *state = mq->impl_state; | ||
821 | size_t msg_size; | ||
822 | |||
823 | GNUNET_assert (NULL != mq); | ||
824 | state->th = NULL; | ||
825 | msg = GNUNET_MQ_impl_current (mq); | ||
826 | |||
827 | if (NULL == buf) | ||
828 | { | ||
829 | GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ); | ||
830 | return 0; | ||
831 | } | ||
832 | |||
833 | if ( (GNUNET_YES == state->receive_requested) && | ||
834 | (GNUNET_NO == state->receive_active) ) | ||
835 | { | ||
836 | state->receive_active = GNUNET_YES; | ||
837 | GNUNET_CLIENT_receive (state->connection, | ||
838 | &handle_client_message, | ||
839 | mq, | ||
840 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
841 | } | ||
842 | |||
843 | msg_size = ntohs (msg->size); | ||
844 | GNUNET_assert (size >= msg_size); | ||
845 | GNUNET_memcpy (buf, msg, msg_size); | ||
846 | state->th = NULL; | ||
847 | |||
848 | GNUNET_MQ_impl_send_continue (mq); | ||
849 | |||
850 | return msg_size; | ||
851 | } | ||
852 | |||
853 | |||
854 | static void | ||
855 | connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, | ||
856 | void *impl_state) | ||
857 | { | ||
858 | struct ClientConnectionState *state = impl_state; | ||
859 | |||
860 | if (NULL != state->th) | ||
861 | { | ||
862 | GNUNET_CLIENT_notify_transmit_ready_cancel (state->th); | ||
863 | state->th = NULL; | ||
864 | } | ||
865 | GNUNET_CLIENT_disconnect (state->connection); | ||
866 | GNUNET_free (impl_state); | ||
867 | } | ||
868 | |||
869 | |||
870 | static void | ||
871 | connection_client_send_impl (struct GNUNET_MQ_Handle *mq, | ||
872 | const struct GNUNET_MessageHeader *msg, | ||
873 | void *impl_state) | ||
874 | { | ||
875 | struct ClientConnectionState *state = impl_state; | ||
876 | |||
877 | GNUNET_assert (NULL != state); | ||
878 | GNUNET_assert (NULL == state->th); | ||
879 | state->th = | ||
880 | GNUNET_CLIENT_notify_transmit_ready (state->connection, | ||
881 | ntohs (msg->size), | ||
882 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
883 | GNUNET_NO, | ||
884 | &connection_client_transmit_queued, | ||
885 | mq); | ||
886 | GNUNET_assert (NULL != state->th); | ||
887 | } | ||
888 | |||
889 | |||
890 | static void | ||
891 | connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq, | ||
892 | void *impl_state) | ||
893 | { | ||
894 | struct ClientConnectionState *state = impl_state; | ||
895 | |||
896 | if (NULL != state->th) | ||
897 | { | ||
898 | GNUNET_CLIENT_notify_transmit_ready_cancel (state->th); | ||
899 | state->th = NULL; | ||
900 | } | ||
901 | else if (NULL != mq->send_task) | ||
902 | { | ||
903 | GNUNET_SCHEDULER_cancel (mq->send_task); | ||
904 | mq->send_task = NULL; | ||
905 | } | ||
906 | else | ||
907 | GNUNET_assert (0); | ||
908 | } | ||
909 | |||
910 | |||
911 | struct GNUNET_MQ_Handle * | ||
912 | GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connection, | ||
913 | const struct GNUNET_MQ_MessageHandler *handlers, | ||
914 | GNUNET_MQ_ErrorHandler error_handler, | ||
915 | void *error_handler_cls) | ||
916 | { | ||
917 | struct GNUNET_MQ_Handle *mq; | ||
918 | struct ClientConnectionState *state; | ||
919 | unsigned int i; | ||
920 | |||
921 | mq = GNUNET_new (struct GNUNET_MQ_Handle); | ||
922 | if (NULL != handlers) | ||
923 | { | ||
924 | for (i=0;NULL != handlers[i].cb; i++) ; | ||
925 | mq->handlers = GNUNET_new_array (i + 1, | ||
926 | struct GNUNET_MQ_MessageHandler); | ||
927 | GNUNET_memcpy (mq->handlers, | ||
928 | handlers, | ||
929 | i * sizeof (struct GNUNET_MQ_MessageHandler)); | ||
930 | } | ||
931 | mq->error_handler = error_handler; | ||
932 | mq->error_handler_cls = error_handler_cls; | ||
933 | state = GNUNET_new (struct ClientConnectionState); | ||
934 | state->connection = connection; | ||
935 | mq->impl_state = state; | ||
936 | mq->send_impl = &connection_client_send_impl; | ||
937 | mq->destroy_impl = &connection_client_destroy_impl; | ||
938 | mq->cancel_impl = &connection_client_cancel_impl; | ||
939 | if (NULL != handlers) | ||
940 | state->receive_requested = GNUNET_YES; | ||
941 | |||
942 | return mq; | ||
943 | } | ||
944 | |||
945 | |||
946 | /** | ||
947 | * Associate the assoc_data in mq with a unique request id. | 750 | * Associate the assoc_data in mq with a unique request id. |
948 | * | 751 | * |
949 | * @param mq message queue, id will be unique for the queue | 752 | * @param mq message queue, id will be unique for the queue |