]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/UdsOp.cc
4 * DEBUG: section 54 Interprocess Communication
11 #include "CommCalls.h"
12 #include "base/TextException.h"
13 #include "ipc/UdsOp.h"
16 Ipc :: UdsOp :: UdsOp ( const String
& pathAddr
):
17 AsyncJob ( "Ipc::UdsOp" ),
18 address ( PathToAddress ( pathAddr
)),
19 options ( COMM_NONBLOCKING
),
22 debugs ( 54 , 5 , HERE
<< '[' << this << "] pathAddr=" << pathAddr
);
27 debugs ( 54 , 5 , HERE
<< '[' << this << ']' );
32 void Ipc :: UdsOp :: setOptions ( int newOptions
)
40 if ( options
& COMM_DOBIND
)
41 unlink ( address
. sun_path
);
42 fd_
= comm_open_uds ( SOCK_DGRAM
, 0 , & address
, options
);
48 void Ipc :: UdsOp :: setTimeout ( int seconds
, const char * handlerName
)
50 AsyncCall :: Pointer handler
= asyncCall ( 54 , 5 , handlerName
,
51 CommCbMemFunT
< UdsOp
, CommTimeoutCbParams
>( this ,
52 & UdsOp :: noteTimeout
));
53 commSetTimeout ( fd (), seconds
, handler
);
56 void Ipc :: UdsOp :: clearTimeout ()
58 commSetTimeout ( fd (), - 1 , NULL
, NULL
); // TODO: add Comm::ClearTimeout(fd)
61 void Ipc :: UdsOp :: noteTimeout ( const CommTimeoutCbParams
&)
63 timedout (); // our kid handles communication timeout
68 Ipc :: PathToAddress ( const String
& pathAddr
) {
69 assert ( pathAddr
. size () != 0 );
70 struct sockaddr_un unixAddr
;
71 memset (& unixAddr
, 0 , sizeof ( unixAddr
));
72 unixAddr
. sun_family
= AF_LOCAL
;
73 xstrncpy ( unixAddr
. sun_path
, pathAddr
. termedBuf (), sizeof ( unixAddr
. sun_path
));
78 CBDATA_NAMESPACED_CLASS_INIT ( Ipc
, UdsSender
);
80 Ipc :: UdsSender :: UdsSender ( const String
& pathAddr
, const TypedMsgHdr
& aMessage
):
83 retries ( 10 ), // TODO: make configurable?
84 timeout ( 10 ), // TODO: make configurable?
87 message
. address ( address
);
90 void Ipc :: UdsSender :: start ()
95 setTimeout ( timeout
, "Ipc::UdsSender::noteTimeout" );
98 bool Ipc :: UdsSender :: doneAll () const
100 return ! writing
&& UdsOp :: doneAll ();
103 void Ipc :: UdsSender :: write ()
106 AsyncCall :: Pointer writeHandler
= asyncCall ( 54 , 5 , "Ipc::UdsSender::wrote" ,
107 CommCbMemFunT
< UdsSender
, CommIoCbParams
>( this , & UdsSender :: wrote
));
108 comm_write ( fd (), message
. raw (), message
. size (), writeHandler
);
112 void Ipc :: UdsSender :: wrote ( const CommIoCbParams
& params
)
114 debugs ( 54 , 5 , HERE
<< "FD " << params
. fd
<< " flag " << params
. flag
<< " [" << this << ']' );
116 if ( params
. flag
!= COMM_OK
&& retries
-- > 0 ) {
117 sleep ( 1 ); // do not spend all tries at once; XXX: use an async timed event instead of blocking here; store the time when we started writing so that we do not sleep if not needed?
118 write (); // XXX: should we close on error so that fd() reopens?
122 void Ipc :: UdsSender :: timedout ()
125 mustStop ( "timedout" );
129 void Ipc :: SendMessage ( const String
& toAddress
, const TypedMsgHdr
& message
)
131 AsyncJob :: AsyncStart ( new UdsSender ( toAddress
, message
));