I'm using aio_write it is working in a debug build but not in release. I've checked the constructor that everything is initialized and I'm not getting any warnings about uninitialized variables. The class collects data that is to be written to disc in 16K chunks. If the data is less than 16K, it works, even in release builds. If the data is larger than 16K, only the first chunk is written. WriteBuffer::ContinueWriteToFile returns WriteFileState_Active indefinitely.
WriteBuffer_posix.h:
class WriteBufferPlatformData
{
public:
WriteBufferPlatformData();
~WriteBufferPlatformData();
aiocb aioData;
WriteBuffer::BufferVector::iterator currentBuffer;
};
WriteBuffer_posix.cpp:
WriteBufferPlatformData::WriteBufferPlatformData() :
aioData(),
currentBuffer()
{
memset(&aioData,0,sizeof(aioData));
aioData.aio_fildes=-1;
}
WriteBufferPlatformData::~WriteBufferPlatformData()
{
if (0<=aioData.aio_fildes) {
close(aioData.aio_fildes);
}
}
WriteBuffer::WriteFileState WriteBuffer::StartWriteToFile(const char * filename)
{
NYMPH_ASSERT(0>m_platformData->aioData.aio_fildes);
m_platformData->aioData.aio_fildes=open(filename,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
NYMPH_ASSERT2(0<=m_platformData->aioData.aio_fildes,"Could not open file for writing: %s (%d)",filename,errno);
if (0>m_platformData->aioData.aio_fildes) {
return WriteFileState_Failed;
}
if (m_buffers.empty()) {
close(m_platformData->aioData.aio_fildes);
m_platformData->aioData.aio_fildes=-1;
return WriteFileState_Complete;
}
m_isWriting=true;
m_platformData->currentBuffer=m_buffers.begin();
return ContinueWriteToFile();
}
WriteBuffer::WriteFileState WriteBuffer::ContinueWriteToFile()
{
NYMPH_ASSERT(0<=m_platformData->aioData.aio_fildes);
if (0!=m_platformData->aioData.aio_nbytes) {
int writeErrno=aio_error(&(m_platformData->aioData));
if (EINPROGRESS==writeErrno) {
return WriteFileState_Active;
}
NYMPH_ASSERT(aio_return(&(m_platformData->aioData))==m_platformData->aioData.aio_nbytes);
m_platformData->aioData.aio_nbytes=0;
++(m_platformData->currentBuffer);
if (m_buffers.end()==m_platformData->currentBuffer) {
close(m_platformData->aioData.aio_fildes);
m_platformData->aioData.aio_fildes=-1;
return WriteFileState_Complete;
}
}
if (0==m_platformData->aioData.aio_nbytes) {
m_platformData->aioData.aio_buf=*(m_platformData->currentBuffer);
if (m_buffers.back()==m_platformData->aioData.aio_buf) {
m_platformData->aioData.aio_nbytes=m_offset;
} else {
m_platformData->aioData.aio_nbytes=kBufferSize;
}
m_platformData->aioData.aio_offset=lseek(m_platformData->aioData.aio_fildes,0,SEEK_END);
if (0!=aio_write(&(m_platformData->aioData))) {
m_platformData->aioData.aio_nbytes=0;
NYMPH_ASSERT(EAGAIN==errno);
if (EAGAIN!=errno) {
close(m_platformData->aioData.aio_fildes);
m_platformData->aioData.aio_fildes=-1;
return WriteFileState_Failed;
}
}
}
return WriteFileState_Active;
}
Despite what I have read in the man page, it seems that calling aio_return is required and changing the NYMPH_ASSERT(aio_return... to NYMPH_VERIFY(aio_return... corrected the problem.
Related
I'm fairly new to Node.js and I am having some issues.
I received error in sonarqube as define a constant instead of duplicating 5 times for "-deleteFlag". how can i resolved this issue.
export class CCGuid {
"-deleteFlag": string;
"#text": string;
constructor(obj: any) {
if (typeof obj === "string") {
this["#text"] = obj;
this["-deleteFlag"] = "N";
} else {
try {
this["-deleteFlag"] = obj["-deleteFlag"];
} catch {
this["-deleteFlag"] = undefined;
}
try {
this["#text"] = obj["#text"];
} catch {
this["#text"] = undefined;
}
}
}
}
export class CCGuid {
"-deleteFlag": string;
"#text": string;
constructor(obj: any) {
const deleteFlag = "-deleteFlag";
if (typeof obj === "string") {
this["#text"] = obj;
this[deleteFlag] = "N";
} else {
try {
this[deleteFlag] = obj[deleteFlag];
} catch {
this[deleteFlag] = undefined;
}
try {
this["#text"] = obj["#text"];
} catch {
this["#text"] = undefined;
}
}
}
}
I think this should do the trick with SQ, at least when it comes to that particular variable. You can do the same with "#text" of course.
After edit: sorry my first answer was broken, I was in a rush and didn't realize what I was really writing down.
Given my updated snippet, you can do the following:
this[deleteFlag']: This will work.
this['-deleteFlag']: This will of course work but Sonar Qube will complain because your use of duplicated string literals.
this.deleteFlag: This won't work because would be looking for a deleteFlag key on the object. Such key doesn't exist, it's '-deleteFlag'.
this['deleteFlag']: this is functionally the same as the line above. Would look for a 'deletFlag' key on the object, which doesn't exist.
Sorry for the confusion! Hope this helps now
A little bit confuse about this simple use case :
I want to add a closure around an other one only with conditions.
For the moment, I only succeed to do this :
if(condition) {
my_root_closure {
my_main_closure {
do_stuff()
}
}
} else {
my_main_closure {
do_stuff()
}
}
I would like to do this without repeat the my_main_closure bloc.
To avoid repetition, you could create new closure that calls my_main_closure and store it in a variable:
def mmc = {
my_main_closure {
do_stuff()
}
}
if(condition) {
my_root_closure( mmc )
} else {
mmc()
}
I'm really stuck and don't know what to do.
I've never worked in Bixby Studio and got that warning "page might be empty".
I've seen two similar posts about this problem, but they didn't help me at all.
item-selection-question {
first warning--> if (isFirstNavPage(page) && isLastNavPage(page)) {
template ("")
second warning--> } else-if (!isLastNavPage(page)) {
template-macro (HANDS_FREE_OPTION_ITEM_SELECTION_MORE_PAGES)
} else {
template-macro (HANDS_FREE_OPTION_ITEM_SELECTION_LAST_PAGES)
}
}
overflow-statement {
template-macro (HANDS_FREE_OPTION_OVERFLOW_STATEMENT)
}
overflow-question {
template-macro (HANDS_FREE_OPTION_OVERFLOW_QUESTION)
}
page-marker {
third warning--> if (!isFirstNavPage(page) && isLastNavPage(page)) {
template-macro (HANDS_FREE_OPTION_LAST_OPTION) {
param (page) {
expression (page)
}
}
}
}
I had a similar warning for,
content {
template ("Here's #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].artist)}.") {
speech ("Here's #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].title)}[ from #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].artist)}].")
}
}
WARN audioInfo.startAudioItemIndex might be empty
I changed the above snippet to,
content {
if(exists(audioInfo.startAudioItemIndex)){
template ("Here's #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].artist)}.") {
speech ("Here's #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].title)}[ from #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].artist)}].")
}
}
}
And it no longer shows the warning.
Try and see if it helps.
I have a clustered program where each thread wants to lock a set of keys.
As I understood the simplest solution using hazelcast:
private void lock(SortedSet<String> objects) {
try {
IMap<String, String> lockMap = getLockMap();
for (; ; ) {
SortedSet<String> lockedObjects = new TreeSet<>();
for (String object : objects) {
try {
boolean locked = lockMap.tryLock(object, 0, null, maxBlockTime, TimeUnit.MILLISECONDS);
if (locked) {
lockedObjects.add(object);
} else {
for (String lockedObject : lockedObjects) {
lockMap.unlock(lockedObject);
}
lockedObjects.clear();
break;
}
} catch (Exception e) {
for (String lockedObject : lockedObjects) {
try {
lockMap.unlock(lockedObject);
} catch(Exception ignored) {
}
}
throw e;
}
}
if (!lockedObjects.isEmpty()) {
return lockedObjects;
}
Thread.sleep(waitTime);
}
}
}
The main problem of this code that this code generates a lot of network traffics and requests to hazelcast. Could somebody recommend how this code can be optimized?
I couldn't find bulk tryLock functionality in the Hazelcast IMap.
Hazelcast does not offer a bulkLock method.
You can optimize this code in various ways, but before we get to that it would be great to know why you want to lock these entries and what you are trying to achieve.
In a piece of Gradle build script, the amount of code i'm repeating is increasing. All tasks have a big part in common, except for a few lines:
task copyZipFile() {
doLast {
def remoteBuildProperties = getRemoteBuildProperties(project)
ant {
taskdef(name: 'ftp',
classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
classpath: configurations.ftpAntTask.asPath)
ftp(server: remoteBuildProperties['host.name'],
userid: remoteBuildProperties['username'],
password: remoteBuildProperties['password'],
remotedir: 'some-folder', // This value differs from call to call
passive: 'true') {
// The next two lines also are different per case, and might be less or more lines
fileset(dir: rootProject.buildDir) { include(name: 'build.zip') }
fileset(dir: rootProject.projectDir) { include(name: 'build.properties') }
}
}
}
}
I don't like to repeat myself, so I'd like to reduce this code to a new helper method that does this trick, and a simple caller, something like:
task copyZipFile() {
doLast {
def remoteBuildProperties = getRemoteBuildProperties(project)
upload(remoteBuildProperties, 'some-folder') {
fileset(dir: rootProject.buildDir) { include(name: 'build.zip') }
fileset(dir: rootProject.projectDir) { include(name: 'build.properties') }
}
}
}
How would I achieve this?
You can pass the inner closure to your upload method as the final parameter. Set the delegate to the original builder delegate so the inner closure calls get handled properly. For example:
def upload(remoteBuildProperties, folder, body) {
ant {
taskdef(name: 'ftp',
classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
classpath: configurations.ftpAntTask.asPath)
ftp(server: remoteBuildProperties['host.name'],
userid: remoteBuildProperties['username'],
password: remoteBuildProperties['password'],
remotedir: folder,
passive: 'true') {
body.delegate = delegate
body()
}
}
}