[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / utils / CIndex / completion_logger_server.py
blob201667117fc2f96976d25b872915d990657f8472
1 #!/usr/bin/env python
2 from __future__ import absolute_import, division, print_function
3 import sys
4 from socket import *
5 from time import strftime
6 import datetime
8 def main():
9 if len(sys.argv) < 4:
10 print("completion_logger_server.py <listen address> <listen port> <log file>")
11 exit(1)
13 host = sys.argv[1]
14 port = int(sys.argv[2])
15 buf = 1024 * 8
16 addr = (host,port)
18 # Create socket and bind to address
19 UDPSock = socket(AF_INET,SOCK_DGRAM)
20 UDPSock.bind(addr)
22 print("Listing on {0}:{1} and logging to '{2}'".format(host, port, sys.argv[3]))
24 # Open the logging file.
25 f = open(sys.argv[3], "a")
27 # Receive messages
28 while 1:
29 data,addr = UDPSock.recvfrom(buf)
30 if not data:
31 break
32 else:
33 f.write("{ ");
34 f.write("\"time\": \"{0}\"".format(datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')))
35 f.write(", \"sender\": \"{0}\" ".format(addr[0]))
36 f.write(", \"data\": ")
37 f.write(data)
38 f.write(" }\n")
39 f.flush()
41 # Close socket
42 UDPSock.close()
44 if __name__ == '__main__':
45 main()