Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: skia/ext/SkFontHost_fontconfig_ipc.cpp

Issue 131006: Linux: move SyncIPC function from Skia to base. (Closed)
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* libs/graphics/ports/SkFontHost_fontconfig_direct.cpp 1 /* libs/graphics/ports/SkFontHost_fontconfig_direct.cpp
2 ** 2 **
3 ** Copyright 2009, Google Inc. 3 ** Copyright 2009, Google Inc.
4 ** 4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License. 6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at 7 ** You may obtain a copy of the License at
8 ** 8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** http://www.apache.org/licenses/LICENSE-2.0
10 ** 10 **
(...skipping 18 matching lines...) Expand all
29 #include "base/unix_domain_socket_posix.h" 29 #include "base/unix_domain_socket_posix.h"
30 30
31 FontConfigIPC::FontConfigIPC(int fd) 31 FontConfigIPC::FontConfigIPC(int fd)
32 : fd_(fd) { 32 : fd_(fd) {
33 } 33 }
34 34
35 FontConfigIPC::~FontConfigIPC() { 35 FontConfigIPC::~FontConfigIPC() {
36 close(fd_); 36 close(fd_);
37 } 37 }
38 38
39 static ssize_t SyncIPC(int fd, uint8_t* reply, unsigned reply_len, int* result_f d,
40 const Pickle& request) {
41 int fds[2];
42 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds) == -1)
43 return false;
44
45 std::vector<int> fd_vector;
46 fd_vector.push_back(fds[1]);
47 if (!base::SendMsg(fd, request.data(), request.size(), fd_vector)) {
48 close(fds[0]);
49 close(fds[1]);
50 return -1;
51 }
52 close(fds[1]);
53
54 fd_vector.clear();
55 const ssize_t r = base::RecvMsg(fds[0], reply, reply_len, &fd_vector);
56 close(fds[0]);
57 if (r == -1)
58 return -1;
59
60 if ((fd_vector.size() > 0 && result_fd == NULL) || fd_vector.size() > 1) {
61 for (std::vector<int>::const_iterator
62 i = fd_vector.begin(); i != fd_vector.end(); ++i) {
63 close(*i);
64 }
65
66 return -1;
67 }
68
69 if (result_fd) {
70 if (fd_vector.size() == 0) {
71 *result_fd = -1;
72 } else {
73 *result_fd = fd_vector[0];
74 }
75 }
76
77 return r;
78 }
79
80 bool FontConfigIPC::Match(std::string* result_family, 39 bool FontConfigIPC::Match(std::string* result_family,
81 unsigned* result_fileid, 40 unsigned* result_fileid,
82 bool fileid_valid, unsigned fileid, 41 bool fileid_valid, unsigned fileid,
83 const std::string& family, int is_bold, 42 const std::string& family, int is_bold,
84 int is_italic) { 43 int is_italic) {
85 Pickle request; 44 Pickle request;
86 request.WriteInt(METHOD_MATCH); 45 request.WriteInt(METHOD_MATCH);
87 request.WriteBool(fileid_valid); 46 request.WriteBool(fileid_valid);
88 if (fileid_valid) 47 if (fileid_valid)
89 request.WriteUInt32(fileid); 48 request.WriteUInt32(fileid);
90 request.WriteBool(is_bold); 49 request.WriteBool(is_bold);
91 request.WriteBool(is_italic); 50 request.WriteBool(is_italic);
92 request.WriteString(family); 51 request.WriteString(family);
93 52
94 uint8_t reply_buf[512]; 53 uint8_t reply_buf[512];
95 const ssize_t r = SyncIPC(fd_, reply_buf, sizeof(reply_buf), NULL, request); 54 const ssize_t r = base::SendRecvMsg(fd_, reply_buf, sizeof(reply_buf), NULL,
55 request);
96 if (r == -1) 56 if (r == -1)
97 return false; 57 return false;
98 58
99 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 59 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
100 void* iter = NULL; 60 void* iter = NULL;
101 bool result; 61 bool result;
102 if (!reply.ReadBool(&iter, &result)) 62 if (!reply.ReadBool(&iter, &result))
103 return false; 63 return false;
104 if (!result) 64 if (!result)
105 return false; 65 return false;
(...skipping 12 matching lines...) Expand all
118 return true; 78 return true;
119 } 79 }
120 80
121 int FontConfigIPC::Open(unsigned fileid) { 81 int FontConfigIPC::Open(unsigned fileid) {
122 Pickle request; 82 Pickle request;
123 request.WriteInt(METHOD_OPEN); 83 request.WriteInt(METHOD_OPEN);
124 request.WriteUInt32(fileid); 84 request.WriteUInt32(fileid);
125 85
126 int result_fd = -1; 86 int result_fd = -1;
127 uint8_t reply_buf[256]; 87 uint8_t reply_buf[256];
128 const ssize_t r = SyncIPC(fd_, reply_buf, sizeof(reply_buf), &result_fd, req uest); 88 const ssize_t r = base::SendRecvMsg(fd_, reply_buf, sizeof(reply_buf),
89 &result_fd, request);
129 90
130 if (r == -1) 91 if (r == -1)
131 return -1; 92 return -1;
132 93
133 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 94 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
134 bool result; 95 bool result;
135 void* iter = NULL; 96 void* iter = NULL;
136 if (!reply.ReadBool(&iter, &result) || 97 if (!reply.ReadBool(&iter, &result) ||
137 !result) { 98 !result) {
138 if (result_fd) 99 if (result_fd)
139 close(result_fd); 100 close(result_fd);
140 return -1; 101 return -1;
141 } 102 }
142 103
143 return result_fd; 104 return result_fd;
144 } 105 }
OLDNEW
« base/unix_domain_socket_posix.cc ('K') | « base/unix_domain_socket_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698