]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/contrib/zeromq/TZmqClient.py
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
20 from cStringIO
import StringIO
21 from thrift
.transport
.TTransport
import TTransportBase
, CReadableTransport
24 class TZmqClient(TTransportBase
, CReadableTransport
):
25 def __init__(self
, ctx
, endpoint
, sock_type
):
26 self
._sock
= ctx
.socket(sock_type
)
27 self
._endpoint
= endpoint
28 self
._wbuf
= StringIO()
29 self
._rbuf
= StringIO()
32 self
._sock
.connect(self
._endpoint
)
35 ret
= self
._rbuf
.read(size
)
39 return self
._rbuf
.read(size
)
41 def _read_message(self
):
42 msg
= self
._sock
.recv()
43 self
._rbuf
= StringIO(msg
)
49 msg
= self
._wbuf
.getvalue()
50 self
._wbuf
= StringIO()
53 # Implement the CReadableTransport interface.
55 def cstringio_buf(self
):
58 # NOTE: This will probably not actually work.
59 def cstringio_refill(self
, prefix
, reqlen
):
60 while len(prefix
) < reqlen
:
62 prefix
+= self
._rbuf
.getvalue()
63 self
._rbuf
= StringIO(prefix
)