Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
b6ff19fb
Kaydet (Commit)
b6ff19fb
authored
Şub 21, 2013
tarafından
Stephan Bergmann
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Clean up code that sends and recvs strings accross the OfficeIPC pipe
Change-Id: I5e85d5e0e4e53f3c61e59430afea15028444018f
üst
f2f8c9d3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
55 deletions
+56
-55
officeipcthread.cxx
desktop/source/app/officeipcthread.cxx
+56
-55
No files found.
desktop/source/app/officeipcthread.cxx
Dosyayı görüntüle @
b6ff19fb
...
@@ -54,12 +54,38 @@ using ::rtl::OUStringBuffer;
...
@@ -54,12 +54,38 @@ using ::rtl::OUStringBuffer;
const
char
*
OfficeIPCThread
::
sc_aShowSequence
=
"-tofront"
;
const
char
*
OfficeIPCThread
::
sc_aShowSequence
=
"-tofront"
;
const
int
OfficeIPCThread
::
sc_nShSeqLength
=
5
;
const
int
OfficeIPCThread
::
sc_nShSeqLength
=
5
;
const
char
*
OfficeIPCThread
::
sc_aConfirmationSequence
=
"InternalIPC::ProcessingDone"
;
const
int
OfficeIPCThread
::
sc_nCSeqLength
=
27
;
const
char
*
OfficeIPCThread
::
sc_aSendArgumentsSequence
=
"InternalIPC::SendArguments"
;
const
int
OfficeIPCThread
::
sc_nCSASeqLength
=
26
;
namespace
{
static
char
const
ARGUMENT_PREFIX
[]
=
"InternalIPC::Arguments"
;
}
namespace
{
static
char
const
SEND_ARGUMENTS
[]
=
"InternalIPC::SendArguments"
;
static
char
const
ARGUMENT_PREFIX
[]
=
"InternalIPC::Arguments"
;
static
char
const
PROCESSING_DONE
[]
=
"InternalIPC::ProcessingDone"
;
// Receives packets from the pipe until a packet ends in a NUL character (that
// will not be included in the returned string) or it cannot read anything (due
// to error or closed pipe, in which case an empty string will be returned to
// signal failure):
OString
readStringFromPipe
(
osl
::
StreamPipe
&
pipe
)
{
for
(
OStringBuffer
str
;;)
{
char
buf
[
1024
];
sal_Int32
n
=
pipe
.
recv
(
buf
,
SAL_N_ELEMENTS
(
buf
));
if
(
n
<=
0
)
{
return
""
;
}
bool
end
=
false
;
if
(
buf
[
n
-
1
]
==
'\0'
)
{
end
=
true
;
--
n
;
}
str
.
append
(
buf
,
n
);
//TODO: how does OStringBuffer.append handle overflow?
if
(
end
)
{
return
str
.
makeStringAndClear
();
}
}
}
}
// Type of pipe we use
// Type of pipe we use
enum
PipeMode
enum
PipeMode
...
@@ -497,18 +523,7 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
...
@@ -497,18 +523,7 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
else
if
(
pThread
->
maPipe
.
create
(
aPipeIdent
.
getStr
(),
osl_Pipe_OPEN
,
rSecurity
))
// Creation not successfull, now we try to connect
else
if
(
pThread
->
maPipe
.
create
(
aPipeIdent
.
getStr
(),
osl_Pipe_OPEN
,
rSecurity
))
// Creation not successfull, now we try to connect
{
{
osl
::
StreamPipe
aStreamPipe
(
pThread
->
maPipe
.
getHandle
());
osl
::
StreamPipe
aStreamPipe
(
pThread
->
maPipe
.
getHandle
());
char
pReceiveBuffer
[
sc_nCSASeqLength
+
1
]
=
{
0
};
if
(
readStringFromPipe
(
aStreamPipe
)
==
SEND_ARGUMENTS
)
int
nResult
=
0
;
int
nBytes
=
0
;
int
nBufSz
=
sc_nCSASeqLength
+
1
;
// read byte per byte
while
((
nResult
=
aStreamPipe
.
recv
(
pReceiveBuffer
+
nBytes
,
nBufSz
-
nBytes
))
>
0
)
{
nBytes
+=
nResult
;
if
(
pReceiveBuffer
[
nBytes
-
1
]
==
'\0'
)
{
break
;
}
}
if
(
rtl
::
OString
(
sc_aSendArgumentsSequence
).
equals
(
pReceiveBuffer
))
{
{
// Pipe connected to first office
// Pipe connected to first office
nPipeMode
=
PIPEMODE_CONNECTED
;
nPipeMode
=
PIPEMODE_CONNECTED
;
...
@@ -563,19 +578,16 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
...
@@ -563,19 +578,16 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
return
IPC_STATUS_BOOTSTRAP_ERROR
;
return
IPC_STATUS_BOOTSTRAP_ERROR
;
}
}
}
}
aArguments
.
append
(
'\0'
);
// finally, write the string onto the pipe
// finally, write the string onto the pipe
aStreamPipe
.
write
(
aArguments
.
getStr
(),
aArguments
.
getLength
());
sal_Int32
n
=
aStreamPipe
.
write
(
aStreamPipe
.
write
(
"
\0
"
,
1
);
aArguments
.
getStr
(),
aArguments
.
getLength
());
if
(
n
!=
aArguments
.
getLength
())
{
rtl
::
OString
aToken
(
sc_aConfirmationSequence
);
SAL_INFO
(
"desktop"
,
"short write: "
<<
n
);
char
*
pReceiveBuffer
=
new
char
[
aToken
.
getLength
()
+
1
];
return
IPC_STATUS_BOOTSTRAP_ERROR
;
sal_Int32
n
=
aStreamPipe
.
read
(
pReceiveBuffer
,
aToken
.
getLength
());
}
pReceiveBuffer
[
n
]
=
'\0'
;
bool
bIsConfirmationSequence
=
aToken
.
equals
(
pReceiveBuffer
);
delete
[]
pReceiveBuffer
;
if
(
!
bIsConfirmationSequence
)
if
(
readStringFromPipe
(
aStreamPipe
)
!=
PROCESSING_DONE
)
{
{
// something went wrong
// something went wrong
return
IPC_STATUS_BOOTSTRAP_ERROR
;
return
IPC_STATUS_BOOTSTRAP_ERROR
;
...
@@ -671,30 +683,16 @@ void OfficeIPCThread::execute()
...
@@ -671,30 +683,16 @@ void OfficeIPCThread::execute()
break
;
break
;
}
}
// notify client we're ready to process its args
// notify client we're ready to process its args:
int
nBytes
=
0
;
sal_Int32
n
=
aStreamPipe
.
write
(
int
nResult
;
SEND_ARGUMENTS
,
SAL_N_ELEMENTS
(
SEND_ARGUMENTS
));
while
(
// incl. terminating NUL
(
nResult
=
aStreamPipe
.
send
(
sc_aSendArgumentsSequence
+
nBytes
,
sc_nCSASeqLength
-
nBytes
))
>
0
&&
if
(
n
!=
SAL_N_ELEMENTS
(
SEND_ARGUMENTS
))
{
((
nBytes
+=
nResult
)
<
sc_nCSASeqLength
)
)
;
SAL_WARN
(
"desktop"
,
"short write: "
<<
n
);
aStreamPipe
.
write
(
"
\0
"
,
1
);
continue
;
// test byte by byte
const
int
nBufSz
=
2048
;
char
pBuf
[
nBufSz
];
nBytes
=
0
;
rtl
::
OStringBuffer
aBuf
;
// read into pBuf until '\0' is read or read-error
while
((
nResult
=
aStreamPipe
.
recv
(
pBuf
+
nBytes
,
nBufSz
-
nBytes
))
>
0
)
{
nBytes
+=
nResult
;
if
(
pBuf
[
nBytes
-
1
]
==
'\0'
)
{
aBuf
.
append
(
pBuf
);
break
;
}
}
}
// don't close pipe ...
rtl
::
OString
aArguments
=
aBuf
.
makeStringAndClear
(
);
rtl
::
OString
aArguments
=
readStringFromPipe
(
aStreamPipe
);
// Is this a lookup message from another application? if so, ignore
// Is this a lookup message from another application? if so, ignore
if
(
aArguments
.
isEmpty
())
if
(
aArguments
.
isEmpty
())
...
@@ -908,11 +906,14 @@ void OfficeIPCThread::execute()
...
@@ -908,11 +906,14 @@ void OfficeIPCThread::execute()
// wait for processing to finish
// wait for processing to finish
if
(
bDocRequestSent
)
if
(
bDocRequestSent
)
cProcessed
.
wait
();
cProcessed
.
wait
();
// processing finished, inform the requesting end
// processing finished, inform the requesting end:
nBytes
=
0
;
n
=
aStreamPipe
.
write
(
while
(
PROCESSING_DONE
,
SAL_N_ELEMENTS
(
PROCESSING_DONE
));
(
nResult
=
aStreamPipe
.
send
(
sc_aConfirmationSequence
+
nBytes
,
sc_nCSeqLength
-
nBytes
))
>
0
&&
// incl. terminating NUL
((
nBytes
+=
nResult
)
<
sc_nCSeqLength
)
)
;
if
(
n
!=
SAL_N_ELEMENTS
(
PROCESSING_DONE
))
{
SAL_WARN
(
"desktop"
,
"short write: "
<<
n
);
continue
;
}
}
}
else
else
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment