]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/UdsOp.cc
4 * DEBUG: section 54 Interprocess Communication
8 #include "base/TextException.h"
10 #include "CommCalls.h"
11 #include "comm/Connection.h"
12 #include "ipc/UdsOp.h"
15 Ipc :: UdsOp :: UdsOp ( const String
& pathAddr
):
16 AsyncJob ( "Ipc::UdsOp" ),
17 address ( PathToAddress ( pathAddr
)),
18 options ( COMM_NONBLOCKING
),
21 debugs ( 54 , 5 , HERE
<< '[' << this << "] pathAddr=" << pathAddr
);
26 debugs ( 54 , 5 , HERE
<< '[' << this << ']' );
31 void Ipc :: UdsOp :: setOptions ( int newOptions
)
39 if ( options
& COMM_DOBIND
)
40 unlink ( address
. sun_path
);
41 fd_
= comm_open_uds ( SOCK_DGRAM
, 0 , & address
, options
);
47 void Ipc :: UdsOp :: setTimeout ( int seconds
, const char * handlerName
)
49 typedef CommCbMemFunT
< UdsOp
, CommTimeoutCbParams
> Dialer
;
50 AsyncCall :: Pointer handler
= asyncCall ( 54 , 5 , handlerName
,
51 Dialer ( CbcPointer
< UdsOp
>( this ), & UdsOp :: noteTimeout
));
52 commSetTimeout ( fd (), seconds
, handler
);
55 void Ipc :: UdsOp :: clearTimeout ()
57 commSetTimeout ( fd (), - 1 , NULL
, NULL
); // TODO: add Comm::ClearTimeout(fd)
60 void Ipc :: UdsOp :: noteTimeout ( const CommTimeoutCbParams
&)
62 timedout (); // our kid handles communication timeout
67 Ipc :: PathToAddress ( const String
& pathAddr
) {
68 assert ( pathAddr
. size () != 0 );
69 struct sockaddr_un unixAddr
;
70 memset (& unixAddr
, 0 , sizeof ( unixAddr
));
71 unixAddr
. sun_family
= AF_LOCAL
;
72 xstrncpy ( unixAddr
. sun_path
, pathAddr
. termedBuf (), sizeof ( unixAddr
. sun_path
));
77 CBDATA_NAMESPACED_CLASS_INIT ( Ipc
, UdsSender
);
79 Ipc :: UdsSender :: UdsSender ( const String
& pathAddr
, const TypedMsgHdr
& aMessage
):
82 retries ( 10 ), // TODO: make configurable?
83 timeout ( 10 ), // TODO: make configurable?
86 message
. address ( address
);
89 void Ipc :: UdsSender :: start ()
94 setTimeout ( timeout
, "Ipc::UdsSender::noteTimeout" );
97 bool Ipc :: UdsSender :: doneAll () const
99 return ! writing
&& UdsOp :: doneAll ();
102 void Ipc :: UdsSender :: write ()
105 typedef CommCbMemFunT
< UdsSender
, CommIoCbParams
> Dialer
;
106 AsyncCall :: Pointer writeHandler
= JobCallback ( 54 , 5 ,
107 Dialer
, 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 :: Start ( new UdsSender ( toAddress
, message
));