--- parser3/src/classes/amqp.C 2026/09/20 11:22:08 1.22 +++ parser3/src/classes/amqp.C 2026/10/09 21:10:38 1.28 @@ -5,41 +5,21 @@ Authors: Konstantin Morshnev */ + +#include "classes.h" #include "pa_vmethod_frame.h" +#include "pa_vamqp.h" #include "pa_request.h" -#include "pa_int.h" -#include "pa_vstring.h" -#include "pa_vhash.h" #include "pa_varray.h" #include "pa_vbool.h" -#include "pa_vvoid.h" -#include "pa_vdouble.h" -#include "pa_vamqp.h" #include "pa_os.h" -#include "pa_globals.h" - -#ifdef WITH_AMQP - -#include -#include -#include - -#ifndef WITHOUT_AMQP_SSL -#include -#endif -#ifdef _MSC_VER -#pragma comment(lib, "rabbitmq.4.lib") -#endif - -#endif - -volatile const char * IDENT_AMQP_C="$Id: amqp.C,v 1.22 2026/09/20 11:22:08 moko Exp $" IDENT_PA_VAMQP_H; +volatile const char * IDENT_AMQP_C="$Id: amqp.C,v 1.28 2026/10/09 21:10:38 moko Exp $" IDENT_PA_VAMQP_H; class MAmqp: public Methoded { public: // VStateless_class - Value* create_new_value(Pool&) { return new VAmqp(); } + Value* create_new_value(Pool& apool) { return new VAmqp(apool); } public: MAmqp(); }; @@ -106,7 +86,7 @@ static void amqp_connect(VAmqp& self, Re int heartbeat_sec = 30; int reconnect_interval_sec = 0; bool tls_specified = false; -#ifndef WITHOUT_AMQP_SSL +#ifdef WITH_AMQP_SSL const char* tls_ca = 0; const char* tls_cert = 0; const char* tls_key = 0; @@ -134,7 +114,7 @@ static void amqp_connect(VAmqp& self, Re } else if(key=="auto_reconnect"){ reconnect_interval_sec=r.process(*value).as_int(); } else if(key=="tls"){ -#ifndef WITHOUT_AMQP_SSL +#ifdef WITH_AMQP_SSL tls_specified = true; if(HashStringValue* tls_options=value->get_hash()){ for(HashStringValue::Iterator t(*tls_options); t; t.next()){ @@ -163,7 +143,7 @@ static void amqp_connect(VAmqp& self, Re amqp_connection_state_t conn = amqp_new_connection(); amqp_socket_t* socket = 0; -#ifndef WITHOUT_AMQP_SSL +#ifdef WITH_AMQP_SSL if(tls_specified) { socket = amqp_ssl_socket_new(conn); if(!socket) @@ -202,7 +182,7 @@ static void amqp_connect(VAmqp& self, Re check(self, rlogin, "login "); } - int channel = 1; + amqp_channel_t channel = 1; amqp_channel_open(conn, channel); amqp_rpc_reply_t ropen = amqp_get_rpc_reply(conn); if(ropen.reply_type != AMQP_RESPONSE_NORMAL){ @@ -463,16 +443,7 @@ static void _publish(Request& r, MethodP } static void _release(Request& r, MethodParams&) { - VAmqp& self=GET_SELF(r, VAmqp); - if(self.fconnection){ - amqp_connection_state_t conn=self.fconnection; - amqp_channel_close(conn, self.fchannel, AMQP_REPLY_SUCCESS); - amqp_connection_close(conn, AMQP_REPLY_SUCCESS); - amqp_destroy_connection(conn); - self.fconnection=0; - self.fchannel=0; - self.fstate=VAmqp::CONNECTION_DEAD; - } + GET_SELF(r, VAmqp).release(); } // to allow both [] and () call syntax @@ -787,7 +758,7 @@ static struct timeval* amqp_wait_tv(stru // message (if any) is still coming // - anything else: a genuine channel/connection close (typically after a protocol violation) - build a // reply so check() can classify it correctly (cheap channel repair vs full reconnect) -static amqp_rpc_reply_t amqp_consume_message_checked(amqp_connection_state_t conn, int channel, amqp_envelope_t* envelope, struct timeval* tv) { +static amqp_rpc_reply_t amqp_consume_message_checked(amqp_connection_state_t conn, amqp_channel_t channel, amqp_envelope_t* envelope, struct timeval* tv) { for(;;) { amqp_rpc_reply_t res = amqp_consume_message(conn, envelope, tv, 0); if(res.reply_type != AMQP_RESPONSE_LIBRARY_EXCEPTION || res.library_error != AMQP_STATUS_UNEXPECTED_STATE)